[Twisted-Python] Python multiprocessing and Twisted stopService - success story

gelin yan dynamicgl at gmail.com
Sun Jan 22 04:47:22 EST 2012


Hi Tom

  Does it work for windows? I use ampoule instead to manage multiple
process.

Regards

gelin yan

On Sat, Jan 21, 2012 at 12:09 AM, Nicolas Toper <ntoper at gmail.com> wrote:

> Hi Tom,
>
> How do you pass data between the parent and its children with
> multiprocessing? It worked fine with Twisted in debug but never in prod :(
>
> Best
> Nicolas
>
>
> On Wed, Jan 18, 2012 at 6:39 PM, Tom Sheffler <tom.sheffler at gmail.com>wrote:
>
>> We are using Py2.6's multiprocessing with Twisted and things are working
>> nicely.  I thought I'd pass on something that seems to work pretty well.
>>  Comments welcome.
>>
>> I am using multiprocessing to spawn long-running worker processes as
>> children of Twisted.  When Twisted is killed, I want the children to be
>> unceremoniously killed as well.  I looked into signal handlers, but
>> creating a service that kills the child processes ended up being simpler
>> and is working well with twistd daemonization.
>>
>> class MultiprocessingStopService(Service):
>>
>>     def stopService(self):
>>         import multiprocessing
>>         for p in multiprocessing.active_children():
>>             p.terminate()
>>         Service.stopService(self)
>>
>> and in my main service maker:
>>
>>         s = MultiService()
>>     stopper  = MultiprocessingStopService()
>>     stopper.setServiceParent(s)
>>
>> Perhaps this will be helpful to someone.
>>
>> -T
>>
>>
>> _______________________________________________
>> Twisted-Python mailing list
>> Twisted-Python at twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>>
>>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120122/83a9ead8/attachment.htm 


More information about the Twisted-Python mailing list