[Twisted-Python] Wrapping a Perspective
rasjidw at gmail.com
Wed Sep 5 22:10:39 EDT 2007
On 9/6/07, Andrew Francis <andrewfr_ice at yahoo.com> wrote:
> If you are willing to use Stackless Python, I would
> recommend you use Christopher Armstrong's
> threadlesss.py blockOn function. This would allow
> Twisted calls to block. A few months ago, I posted a
> solution that would work, but it would be overkill.
I have read about Stackless, and it looks like it would be really fun
to play with. But I don't think my employer would be keen to go as
'fringe' as Stackless.
> I am also curious why you can't use inline callbacks?
I've only been playing with Twisted seriously for a couple of weeks,
but as far as I understand inline callbacks, they just make the code
'look' synchronous, but the end result is still a deferred. In my
playing with them, they make twisted code much more succinct and
generally easier to read, but it is all still really just deferreds
underneath and there is no actual blocking going on.
I want to have my python code being called from an external process
via COM, and the external process will expect to be calling a class
method that will do something (blocking as long as required) and then
return the result. Rewriting the external app to deal with everything
being async is not an option.
I'd love to be shown that I'm wrong on this, but can't see how inline
callbacks solve my problem.
> > So my question really is:
> > What are the problems / brawbacks with running the
> > twisted reactor in
> > a non-main thread, provided all calls to the reactor
> > are done through
> > twisted.internet.blockingCallFromThread?
> I have used threads with Twisted and Stackless and
> found I took a performance hit. Also I found it
> prudent to heed the advice and try not to mix threads
> with Twisted (or Stackless)
The other option I have thought about is using the Python processing
module (http://pypi.python.org/pypi/processing), which would have the
com server and the twisted client each in their own python process
(and thus Twisted would then be single threaded), although it is
unclear to me if this is making the situation better or worse in
More information about the Twisted-Python