[Twisted-Python] shared list in factory, mutexes?
Itamar Shtull-Trauring
itamar at itamarst.org
Mon Apr 14 07:27:38 MDT 2008
On Mon, 2008-04-14 at 12:35 +0200, Gabriel Rossetti wrote:
> I'm wondering if maybe I'm misunderstanding something here, when several
> messages arrive, what happens, are they processed in parallel, are they
> put in a queue and processes sequentially?
Sequentially. Twisted does not expose use of threads to user-level
APIs... and Twisted APIs are not thread-safe, other than
reactor.callFromThread.
> If I receive a message, do
> some heavy processing/io/potentially blocking code in a thread using
> twisted's threading module, and before it's done, I get another
> connection + message that needs the same thing to be done, what
> happens?
reactor.callInThread (and therefore deferToThread) are built on top of a
thread-safe Queue. Just make sure your scheduled tasks are not calling
back into Twisted but are rather self-contained units of work.
More information about the Twisted-Python
mailing list