On 11/07/2011 08:06 AM, Roberto De Ioris wrote:
> 
>> On 11/06/2011 08:23 PM, Roberto De Ioris wrote:
>>>
>>>> On 11/06/2011 07:58 AM, Roberto De Ioris wrote:
>>
>>>>
>>>> --attach-daemon works file.
>>>>
>>>
>>> attach-daemon create a new process group, so if you call fork() and
>>> simply
>>> run code the children will be killed too.
>>>
>>> How do you create children ? If you call setsid(), a new process group
>>> will be created so uWSGI will not be able to kill them.
>>
>>
>> I naively used sobprocess.Popen
>> # Simplified code snippet
>> import subprocess
>> log_file = open( 'stdout.log', 'wb')
>> err_log_file = open('stderr.log', 'wb')
>> cmd = [ 'cmd' , 'param1', 'param2') ]
>> proc = subprocess.Popen(cmd, stdout=log_file, stderr=err_log_file)
>> proc.wait()
>>
> 
> Looks good.
> #!/usr/bin/env python
import os, sys
import subprocess

os.chdir( os.path.dirname(__file__) )

log_file = open('spawn_test.log', 'wb')
err_log_file = open('spawn_test_err.log', 'wb')
proc = subprocess.Popen([ './child.py' ] , stdout=log_file,
stderr=err_log_file)
proc.wait()
Check with ps if the spawned processes are all under the same process group.
> Maybe some of your children call setsid()/setpgroup()
> 

Everything looks fine in my opinion. However the child process doesn't
die :-( .

I have two simple python scripts:
#!/usr/bin/env python
# #################### the daemon ######
import os, sys
import subprocess

os.chdir( os.path.dirname(__file__) )

log_file = open('spawn_test.log', 'wb')
err_log_file = open('spawn_test_err.log', 'wb')
proc = subprocess.Popen([ './child.py' ] , stdout=log_file,
stderr=err_log_file)
proc.wait()

#!/usr/bin/env python
# ################ The child
import sys, time
for i in range(200):
    print i
    sys.stdout.flush()
    time.sleep(3)

# ######### The uwsgi xml file
<uwsgi>
 <uid>nginx</uid>
 <gid>nginx</gid>
 <socket>127.0.0.1:1234</socket>
 <master />
 <workers>8</workers>
 <attach-daemon>/path/to//spawn_test.py</attach-daemon>
 <pidfile>/var/run/uwsgi/uwsgi.pid</pidfile>
 <daemonize>/var/log/uwsgi/uwsgi.log</daemonize>
 <env>APP_VAR=var</env>
 <pp>/my_ppath</pp>
 <virtualenv>/myvirtenvn</virtualenv>
 <module>my.module</module>
</uwsgi>

# my ps command
ps axo 'user,group,euser,egroup,pid,pgid,cmd' | grep nginx

# PS BEFORE STARTING:
Nothing

# AFTER STARTING
. . .
nginx    nginx    nginx    nginx     5784  5775 /virtenv/bin/uwsgi -x
/etc/uwsgi/uwsgi-conf.xml # this line multiple times
nginx    nginx    nginx    nginx     5785  5775 python
/path_to/spawn_test.py
nginx    nginx    nginx    nginx     5786  5775 python ./child.py


# AFTER stopping
nginx    nginx    nginx    nginx     5786  5775 python ./child.py

Perhaps somebody has an idea.












_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to