I'm running a background database processing task, and I only want to
have ONE task running so I don't have to worry about race conditions.
What is the best way to do this?

I run this task from a cron @reboot. It runs this script:

while True:
    time.sleep(10)
    process_queue()

I'm worried that I might accidentally run two web2py processes at the
same time, each starting a cron job, and then I'd have two running and
mess up my data. So I want this script to check to see if another one
is currently running, and if so, to give up.

I considered making an entry in a database like
"background_task_running = true", but how can I guarantee that it gets
set to false if my web2py crashes? I don't want to have to manually
reset that field all the time.

Is it best to see if this process is currently running on the machine,
with os.system('ps aux | grep background_work.py'), but this isn't
cross-platform, and won't work if the process is running on another
machine. Is there a way to check if another of these processes is
connected to the postgresql database?

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to