[Twisted-Python] Mixing Python threads and Twisted code

Alexandre Quessy alexandre at quessy.net
Sun Dec 7 16:05:23 MST 2014


Hello everyone,
Thanks Jean-Paul for the tips!

Now, I figured out that this thread was calling some callbacks, which in
turn were either sending some UDP using a child of Twisted's datagram
protocol, or launching processes using t.p.procutils.which and
t.i.utils.getProcessOutputAndValue. None of this is guaranteed to be
thread-safe, according to
http://twistedmatrix.com/documents/current/core/howto/threading.html.

I just added a reactor.callFromThread before calling my callbacks, and it
should now be much faster...

Best,

2014-12-06 13:47 GMT-05:00 <exarkun at twistedmatrix.com>:

> On 06:15 pm, alexandre at quessy.net wrote:
>
>> Hello everyone,
>>
>> What happens if some code starts a thread while I am using Twisted's
>> reactor?
>>
>
> Nothing special.
>
>> Here is what I need to use:
>> https://github.com/ekulyk/PythonPusherClient/blob/master/pusherclient/
>> connection.py#L12
>>
>> This thread polls some socket to handle received TCP messages. It appears
>> it has been very slow in production. Is it this mix of twisted and
>> non-twisted threading that causes this brutal slowdown?
>>
>
> Not likely.  Twisted doesn't have its own threading implementation.
> Twisted has a threadpool module which is a thin layer on top of Python's
> threading module.
>
>> If so, how can I
>> easily speed it up without having to twistify the library I need to use?
>> (and practically rewrite it)
>>
>
> Profile it.  Find the particular operations that are slow.  Then you'll be
> one step closer to knowing how to speed things up.
>
> Jean-Paul
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



-- 
Alexandre Quessy - 亚历山大 - ألكسندر
http://alexandre.quessy.net - Artiste en nouveaux médias
http://perte-de-signal.org - Membre de Perte de signal
http://sourcelibre.net - Développement logiciel et conception de sites Web
http://labalab.ca - Impliqué dans LabàLab - communauté de pratique en arts
numériques
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20141207/8ebc6d04/attachment-0002.html>


More information about the Twisted-Python mailing list