[Twisted-Python] Mixing Python threads and Twisted code

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Sat Dec 6 11:47:51 MST 2014


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




More information about the Twisted-Python mailing list