470,599 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,599 developers. It's quick & easy.

detached subprocess

After struggling with os.spawnxxx to get a detached process I tried using
Pyhton2.4's new subprocess module.

I struggled with that as well even when trying to use the creation flags for
DETACHED_PROCESS 0x8 and CREATE_NEW_PROCESS_GROUP = 0x200

I am using the following cgi script parent.cgi

#!c:/python24/python.exe -u
print 'content-type: text/plain'
print
print 'DONE'
import subprocess
pid = subprocess.Popen(['c:/python24/pythonw.exe',
'c:\\tmp\\child.py', 'arg1', 'arg2'], creationflags=0x208).pid
print pid
#end of parent script
child is a simple time delay

#child.py
import time, sys, os
time.sleep(10)
print 'stdout IN THE CHILD'
print >>sys.stderr, 'stderr IN THE CHILD'
#end of child
When I run the parent.cgi script through apache I see no output in the browser
for 10 seconds; when the child dies (as observed using procexp) I see the expected

DONE
3256

In other words it seems impossible to get standard subprocess.py to detach the
child process properly.

However, if I hack subprocess.py to alter the bInheritHandles flag passed into
CreateProcess (line 718) from the constant 1 to

not (creationflags & 0x8) and 1 or 0

Is this a buglet or a feature request? It seems subprocess punts on closefds for
mswindows, but setting bInheritHandles to 0 seems to work fine ie when it is 0
my test seems to indicate that the parent has finished and gone to heaven long
before the child ends its sleep. Of course it may be that it's just the handles
that are being held.
--
Robin Becker

Jul 19 '05 #1
0 2176

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by jurson | last post: by
3 posts views Thread by Darren Dale | last post: by
5 posts views Thread by Grant Edwards | last post: by
9 posts views Thread by Phoe6 | last post: by
10 posts views Thread by JD | last post: by
12 posts views Thread by bhunter | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.