[twisted-python] Communication between GUI thread and twisted thread.

Andrew Bennetts andrew-twisted at puzzling.org
Mon Jun 18 02:58:25 EDT 2007

甜瓜 wrote:
> Hi, my program has two parts running in two threads. One is a GUI
> layer, the other is a twisted layer for communication with a remote
> server. Sometimes, a button is clicked in GUI to notice the twisted
> thread to send out some data. (reactor.callFromThread should be used,
> right?)
> In twisted part, I use reactor.connectTCP('x.x.x.x', port,
> MyFactory()) to connect with remote server. MyFactory will create an
> instance of MyProtocol, and MyProtocol has a method 'sendSpecialMsg'
> for doing real jobs.
> However, in GUI part, how can I invoke 'sendSpecialMsg' function? Even
> I cannot get the MyProtocol instance! Because connectTCP and MyFactory
> hide the protocol object. I'm sure it is a common problem for
> beginners, Could you give me some advice?

Something like ClientCreator (a convenient way to connect and get a protocol
instance when it is connected) with blockingCallFromThread (in SVN Twisted, so
the calling thread can get access to the result of the deferred from
ClientCreator) would probably do the trick.

If these aren't directly usable, you may find inspiration from looking at their


More information about the Twisted-Python mailing list