Paste waits for a process despite double fork popen

13 views
Skip to first unread message

Ted Goldstein

unread,
Mar 17, 2014, 3:53:28 PM3/17/14
to paste...@googlegroups.com
I am trying to fork a program from within Paste and talk to it through python popen.    Everything works as expected except that somewhere in Threadpool, the calling thread waits for the child process to exit. You can see this by running the following simple paste program that does a popen on /bin/sleep 10.  

My expectation is that the invoking HTTP request would return immediately,

 In fact, I don't see any wait calls in Paste. So I am not even sure how this hangs up.

% python minimal.py 10000

and in another window:

% curl localhost:10000


I would have expected that the UNIX double fork would divorce the child process from the server process. Somehow, it isn't.

Does anybody know why and what I should do to get the invoking request to return immediately?

Thanks,
Ted



from paste import httpserver
import os, subprocess, sys

class ObjectPublisher:
    def __call__(self, environ, start_response):
if os.fork() == 0:
   if os.fork() == 0:
os.setsid() 
os.umask(0) 
subprocess.Popen([ "/bin/sleep", "10"])
                print "after popen"
os._exit(0)
   else:
os._exit(0)
else:
            print "after fork"
   start_response('200 OK', [('content-type', 'text/html')])
            print "before return"
   return ["Come back soon"]


app = ObjectPublisher()
httpserver.serve(app, host='127.0.0.1', port=sys.argv[1])


Reply all
Reply to author
Forward
0 new messages