I don't get the "it's not applicable in this case" part. The way you start 
them on web2py is the same one you can use with the scheduler....

Starting child processes from webserver main process is never safe because 
of the problem you're facing. The second you kill the webserver process 
(or, in more advanced webserver, when it realizes it's a process lasting 
too long) the child process is killed too (a webserver is "made" for 
responding quickly, so advanced ones try to free up "hanging" resources). 
However, this is not a problem on web2py per se, but on how python handles 
processes spawned. If you can't get a normal python script to launch a 
process that is not killed when the main python program is killed, then 
web2py can't really help with that.

Two tricks: instead of launching processes directly, you can use *start*program 
on Windows or the 
*at* program on Linux. Then the process is child of start or at, not your 
app, and it shouldn't be killed.

Another trick: If you just need to launch them and never communicate with 
those again, did you try with
import subprocess
subprocess.Popen([whatever], stdout=subprocess.PIPE, 
stderr=subprocess.PIPE, stdin=subprocess.PIPE)

?

On Thursday, November 1, 2012 1:50:16 PM UTC+1, Richard Penman wrote:
>
> Would be great to use the new scheduler but doesn't seem applicable in 
> this case. I have no difficulty starting these processes.
>
> As described in OP, the problem is these are child processes which makes 
> them dependent on the main web2py process. So I was wanting these to 
> be independent processes - or is there a better way?
>
>
>
> On Thursday, November 1, 2012 3:45:28 PM UTC+11, Massimo Di Pierro wrote:
>>
>> Please use the scheduler.
>>
>> On Wednesday, 31 October 2012 21:56:47 UTC-5, Richard Penman wrote:
>>>
>>> Hello,
>>>
>>> I create a new process after each form submission to parse some data:
>>> subprocess.Popen(['python', parser_script], 
>>> cwd=os.path.dirname(parser_script))
>>> (The parser_script is independent of web2py)
>>>
>>> This parsing can take days and multiple parsers need to be executed at 
>>> once.
>>> However if the web2py process is ended these child processes are also 
>>> killed. 
>>> How can I run these as independent orphan processes?
>>>
>>> A Linux only solution is fine or cross platform if practical.
>>>
>>> Richard
>>>
>>

-- 



Reply via email to