[Twisted-Python] multiple workers

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Thu Sep 2 08:01:41 EDT 2010


On 1 Sep, 10:53 pm, ruslan.usifov at gmail.com wrote:
>Hello
>
>I try to write twisted based daemon that work in multiple workers, like
>this:
>
>from twisted.internet import reactor;
>from proxy import FASTCGIServerProxyFactory;
>import os;
>
>reactor.listenUNIX("/tmp/twisted-fcgi.sock", 
>FASTCGIServerProxyFactory());
>
>for i in xrange(3):
>  l_pid = os.fork();
>
>  if(l_pid == 0):
>    break;
>
>reactor.run()
>
>I creatae 4 wokers(by num of CPU cores). Im my test all ok, but when i
>shutdown daemon i got follow error 3 times (because every worker try to
>unlink sock file: /tmp/twisted-fcgi.sock):

Using fork this way isn't supported.  Either fork before you import any 
Twisted modules, or use reactor.spawnProcess to create workers instead. 
If you must share a single listening socket amongst all the workers, you 
might be interested in <http://twistedmatrix.com/trac/ticket/4387>.

Jean-Paul



More information about the Twisted-Python mailing list