[Twisted-Python] Abouth threads in twisted.
newptcai at gmail.com
Tue Aug 19 08:08:19 EDT 2008
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?
from twisted.internet import reactor
"""do something that isn't thread-safe"""
"""Run in thread-safe manner."""
reactor.callFromThread(notThreadSafe, 3) # will run 'notThreadSafe(3)' in
the event loop
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
it might damage the event look as most twisted APIs are not thread safe.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python