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. Advertisements

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,383
    Alberto Morales
    Sep 5, 2003
  2. Nishi Bhonsle
    Replies:
    2
    Views:
    24,942
    pahujadeepanshu
    Nov 30, 2009
  3. Sigfried Manner

    Linux / how to check if subprocess is still alive

    Sigfried Manner, Sep 1, 2003, in forum: C Programming
    Replies:
    7
    Views:
    1,108
    Irrwahn Grausewitz
    Sep 1, 2003
  4. The Dark Seraph

    Detached interpreter threads

    The Dark Seraph, May 27, 2004, in forum: Python
    Replies:
    0
    Views:
    385
    The Dark Seraph
    May 27, 2004
  5. Replies:
    2
    Views:
    1,074
  6. hiral
    Replies:
    2
    Views:
    801
    Jean-Michel Pichavant
    May 5, 2010
  7. Edmond Kachale
    Replies:
    2
    Views:
    300
    Dave Howell
    Sep 22, 2010
  8. Moshe Katz
    Replies:
    2
    Views:
    297
    Moshe Katz
    May 2, 2004
Loading...