[Twisted-Python] Abouth threads in twisted.
newptcai at gmail.com
Tue Aug 19 21:05:59 EDT 2008
Thanks for your reply! But I think I have to read some source code
of twisted to make sure what was happening behind callFromThread.
On Tue, Aug 19, 2008 at 11:58 PM, Itamar Shtull-Trauring <
itamar at itamarst.org> wrote:
> On Tue, 2008-08-19 at 20:08 +0800, Peter Cai wrote:
> > Hi All,
> > QUESTION 1 : callFromThread
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > I found this code snippet in twisted manual book.
> > But I don't quite get it.
> > What does "run 'notThreadSafe(3)' in the event loop" means?
> > Does the reactor promise that all those "notThreadSafe" functions
> > be called one by one so they won't interfere each other?
> They will be called in main thread, the one where you did reactor.run()
> > QUESTION 2 : Integrated with a threaded 3rd party library.
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > I have a C library which using a work threaded pool model. It's
> > interface is like this.
> > void runWorkAsyn(int args, void pcallbackfunc(int));
> > When runWorkAsyn is called, it dispatch work to a thread in its
> > own thread pool and call 'pcallbackfunc' in that thread when it's
> > done.
> > I really got confused by how use this lib from twisted in a thread
> > safe way.
> > If I use a python callback function as pcallbackfunc and touch the
> > reactor from it,
> > it might damage the event look as most twisted APIs are not thread
> > safe.
> Rather than passing in callable "doSomething" as callback, pass in:
> "lambda *args: reactor.callFromThread(doSomething, *args)".
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python