"Bad file descriptor" in HTTPServer using Multiprocessing.

Adam Tauno Williams awilliam at opengroupware.us
Fri Jan 15 13:50:02 EST 2010


On Sun, 2010-01-10 at 14:45 -0500, Adam Tauno Williams wrote:
> I have a Python multiprocessing application where a master process
> starts server sub-processes and communicates with them via Pipes;  that
> works very well.  But one of the subprocesses, in turn, starts a
> collection of HTTPServer 'workers' (almost exactly as demonstrated in
> the docs).  This works perfectly.... so long as the subprocess that
> starts the HTTPServer workers is the *first* process started by the
> master process.  Otherwise the HTTPServer's serve_forever immediately
> abends with: "(9, 'Bad file descriptor')"

Performing an sys.stdin.close() before the subprocess spawned its
workers seems to have resolved the issue.

> I'm confused why the order of starting the processes matter, especially
> given that the HTTPServer's are start in a subprocess of a subprocess.
> The master doesn't do much of anything between starting each subprocess
> (which it does in a loop;  identify all the subprocesses to start, and
> start them.).
> 
> subprocess
> --------------------
> ......
>             self._httpd = HTTPServer((HTTP_HOST, HTTP_PORT), HTTPRequestHandler)
>             print 'HTTPServer created.'
>         for i in range(10):
>             p = multiprocessing.Process(target=serve_forever, args=(self._httpd, i, self))
>             self._workers.append(p)
>             p.start()
> 
> .....
> def serve_forever(server, i, control):
>     print 'coils.http starting HTTP worker #{0}'.format(i)
>     try:
>         server.serve_forever()
>     except KeyboardInterrupt:
>         pass
>     except Exception, e:
>         control.log.exception(e)
>         print 'coils.http worker #{0} abended with exception.'.format(i)
>         print e
>     return
> OpenGroupware developer: awilliam at whitemice.org
> <http://whitemiceconsulting.blogspot.com/>
> OpenGroupare & Cyrus IMAPd documenation @
> <http://docs.opengroupware.org/Members/whitemice/wmogag/file_view>






More information about the Python-list mailing list