0

I have a python file color.py that I can call using python color.py and it performs a task and when completed deletes a file. I've tried adding a cronjob to start it but it never starts.

Here's the python code

def colour_images(images=None):
    try:
        if images == None:
            images = list_files()

        failed = open('failed.txt')
        failed_files = [x.replace('\n','') for x in failed.readlines()]

        for filename in failed_files:
            if filename in images:  
                images.remove(filename)

        #print "Conversion starting total: {0} images".format(len(images))
        #counter = len(images)

        #check if there's a lock
        try:
            proccess_locked = open('memory.lock')
            proccess_locked.close()
            locked = True
        except IOError:
            locked = False

        if locked == False:
            lock = open('memory.lock','w')
            lock.close()

            for image in images:
                new_name = "coloured/" + image
                result = os.system("th colorize.lua {0} {1}".format(image, new_name))
                os.system('rsync {0} sammy@pluscolor.co.ke:/home/sammy/revamp/revamp/media/new_colour/'.format(new_name))
                os.remove(new_name)

                if result != 0:
                    failed = open('failed.txt', 'a')
                    failed.write(image+'\n')
                    failed.close()
                else:
                    os.remove(image)

                #counter -= 1
                #print "{0} remaining".format(counter)
                #print "{0} -> {1}".format(image, new_name)
            os.remove("memory.lock")
    except Exception, e:
        log_error = ('error.log','w')
        log.write(str(e)+'\n')
        log.close()


if __name__ == '__main__':
    colour_images()

and the cron command

*/1 * * * * /usr/bin/python /root/images/color.py >> /var/log/color.log 2>&1
4
  • Are you sure it never starts? Or does it simply fail to complete? Cron is rarely the real problem.
    – user535733
    Jul 15 '17 at 19:26
  • I've found out it fails to complete, I've asked a question on this here stackoverflow.com/questions/45136963/… Jul 17 '17 at 6:05
  • how did you set up the cronjob? I had an issue once it was setup as a cronjob for a specific user but the file could not be accessed by that user. Jul 18 '17 at 8:06
  • I've now since known the issue is with the torch command "th" which fails to load correctly and create an image. Jul 18 '17 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.