Forums

long running task check not working

Hi,

I noticed recently that the long running check to see if the task is already running before running it doesn't seem to work. I ended up with a bunch of tasks running in my scheduled tasks since my task runs infinitely.

What's the fix? Is anyone experiencing this?

lock_socket = None  # we want to keep the socket open until the very end of
                    # our script so we use a global variable to avoid going
                    # out of scope and being garbage-collected
def is_lock_free():
    global lock_socket
    lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
    try:
        lock_id = "name.script"   # this should be unique. using your username as a prefix is a convention
        lock_socket.bind('\0' + lock_id)
        print("acquired")
        logging.debug("Acquired lock %r" % (lock_id,))
        return True
    except socket.error:
        # socket already locked, task must already be running
        print("failed")
        logging.info("Failed to acquire lock %r" % (lock_id,))
        return False

if not is_lock_free():
    sys.exit()

That sounds very strange! I've checked the system to make sure there's no obvious reason why that would happen, and I can't see anything going on that shouldn't be.

Which of your tasks is causing the problem? Can I take a look at your code? We can see it from the admin interface, but we always ask for permission first.