[Twisted-Python] Advice on Writing a Custom Twisted Stackless Reactor
Andrew Francis
andrewfr_ice at yahoo.com
Thu Jan 11 14:46:17 MST 2007
Date: Wed, 10 Jan 2007 18:32:43 -0500
From: Jean-Paul Calderone <exarkun at divmod.com>
Subject:
To: Twisted general discussion
<twisted-python at twistedmatrix.com>
Message-ID:
<20070110233243.11447.1076809328.divmod.quotient.12503 at ohm>
Content-Type: text/plain; format=flowed
>Okay. I see that you're writing stackless
integration
>using TSR. I'm not sure what the point of this is.
>Can you explain the functionality that's gained by
>doing this, rather than using something like what's
in >Chris Armstrong's sandbox in threadless.py?
Thank you Jean-Paul for your response. My goal is to
write a custom Twisted reactor for Stackless Python.
Although I have had success writing programmes that
use deferred (for client HTTP calls) and HTTP request
handlers, I have had problems doing both
simultaneously in one programme.
Some context : I am prototyping WS-BPEL (Web services
Business Process Execution Language) processors. In
the WS-BPEL language, it is possible for some
process's "threads" to act as a server and other
"threads" to act as a client simultaneously.
The problem that I have found is that when Twisted
blocks waiting for a server request, Stackless will
also block, hence no progress on other tasklets that
could execute. I thought I got around this problem by
using task.LoopingCall/() that would issue a
stackless.schedule() at regular intervals. However
this approach turns out to be problematic. I thought I
could solve the problem by placing Twisted in a thread
but no. The main problem with placing Twisted in a
thread is that I seem to lose the deferred (and I
don't believe I am getting deadlock).
>Can you explain the functionality that's gained by
>doing this,
1. I solve my problem in a clean fashion.
2. If I write a custom Stackless Reactor, then I have
a solution that conforms to the way Twisted does
stuff. I think would make it easier for others to use
my stuff.
>rather than using something like what's in Chris
>Armstrong's sandbox in threadless.py?
Chris's approach looks like the approach I currently
use.
>Threaded select reactor actually isn't the same kind
>of reactor as the rest of these, since it isn't
>intended to be used via the normal reactor API (ie,
>run).
Right now I am using Twisted 2.4 with Stackless 2.4.3.
For now, I would like to build on top of
ThreadedSelectReactor.
Back to my original question, given my previous
example's "main loop", do I simply use interleave() to
get my processor to call Twisted?
Cheers,
Andrew
____________________________________________________________________________________
Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index
More information about the Twisted-Python
mailing list