Detect web2py main process exit on cron process

42 views
Skip to first unread message

Álvaro José Iradier

unread,
Mar 5, 2013, 4:23:35 PM3/5/13
to web...@googlegroups.com
Hi,

on my web2py application on windows, I have a cron task that runs for a long time. I noticed a new process is spawned for every cron job.. If the main web2py process exists (for example if I try to terminate the process, or close the web2py window), it will not exit until the cron process is finished (is it waiting for the child processes to finish?). Am I right, or do I get something wrong?

So my question is, Is there a way to detect from the cron process that the main web2py process is exiting, in order to finish inmediately, but clean? I thought of using the getppid() from the cron process for getting the parent process id, but it is not available on windows. Could the main web2py process send a "terminate" or "interrupt" signal or similar to the still running cron processes? This way the process would be killed, or could trap the signal and exit cleanly.

Thanks very much.



Álvaro J. Iradier

unread,
Mar 6, 2013, 8:05:57 AM3/6/13
to web...@googlegroups.com
Proposition:

I have made a small proposed patch to newcron.py, in order to keep a list of cron subprocesses and send a terminate signal when web2py exists. See attached newcron.py.diff. A lock should be added when accessing the _cron_subprocs list, to avoid thread concurrency.

Also, I noticed that newcron.stopcron() is called when closing the widget window if the web server was started. But if the web server was not started, it will not be called, which is strange, as cron is started before the web server. The second attached patch (widget.py.diff) fixes this to call newcron.stopcron() on exit.

I guess same fix should be applied for winservice.py, and similar for the --nogui case.

What do you think about this proposed changes?

Thanks.






--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/NzETk-m6Liw/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
(:=================================:)
 Alvaro J. Iradier Muro - aira...@gmail.com
newcron.py.diff
widget.py.diff

Massimo Di Pierro

unread,
Mar 10, 2013, 11:22:41 AM3/10/13
to web...@googlegroups.com
Your patch is in trunk. Can you please check it? Thank you Alvaro.
Reply all
Reply to author
Forward
0 new messages