[Twisted-Python] Interactive Twisted client (newbie question?)

Glyph Lefkowitz glyph at divmod.com
Wed Jan 5 10:18:13 EST 2005


On Mon, 2005-01-03 at 23:00 +0000, Jon Blower wrote:

> I'm sure I'm not the first to ask this sort of question, but I've looked through
> the docs and example code and haven't been able to track down an answer.  I'd
> be very grateful for any pointers that anyone could offer.

This is why I often suggest the use of 'twistd' for running your Twisted
code - the reactor.run() call is confusing, because it makes it seem as
though it's your code's responsibility to start and stop the reactor,
and possibly to do things before or after that has happened.

Even if you need to start the reactor yourself - for example, if you are
writing a GUI program - it is best to abstract out the reactor
start/stop far from your application code.

If I understand the core of your question correctly, it's "How do I use
Twisted at the interactive Python interpreter?"

There is no easy answer.  Twisted is not well-suited towards use at a
normal Python prompt, because the normal Python prompt is not
event-driven.  There have been a few different forays into interactive
Python/Twisted integration.  The 1.3.0 release includes a 'manhole'
client/server pair which will allow you to log in and run python code
inside a running Twisted process.  JP Calderone has recently done quite
a bit of work on a new, better interactive interpreter (including SSH
access and command-line editing) which looks more like a regular Python
prompt.

Although there are several different avenues you can take to get there,
what you probably want to arrive at is a Twisted server that is
listening on one port for Python commands, and on another for whatever
protocol it is you are trying to implement.  For convenience, it may be
useful for the "port" that it's listening on to actually be standard
I/O.  This is possible using twisted.internet.stdio.






More information about the Twisted-Python mailing list