detached subprocess

Discussion in 'Python' started by Robin Becker, May 23, 2005.

  1. Robin Becker

    Robin Becker Guest

    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
    Robin Becker, May 23, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bill Laird
    Replies:
    1
    Views:
    2,158
    Alberto Morales
    Sep 5, 2003
  2. The Dark Seraph

    Detached interpreter threads

    The Dark Seraph, May 27, 2004, in forum: Python
    Replies:
    0
    Views:
    299
    The Dark Seraph
    May 27, 2004
  3. Replies:
    2
    Views:
    946
  4. Edmond Kachale
    Replies:
    2
    Views:
    137
    Dave Howell
    Sep 22, 2010
  5. Moshe Katz
    Replies:
    2
    Views:
    142
    Moshe Katz
    May 2, 2004
Loading...

Share This Page