[Twisted-Python] integrating a python REPL into my existing twisted application
Andrew Bennetts
andrew at bemusement.org
Wed May 25 23:08:13 MDT 2011
Benjamin Rutt wrote:
> Dear twisted-python,
> �
> I�m trying to integrate a python REPL into my existing twisted 8.2.0
> client-side program (which talks to another twisted server running a
> custom protocol).� This client side program uses
> twisted.internet.stdio.StandardIO already to interact with the user, to
> read commands from the user and send them to the server.� What�s the best
> way to add functionality to drop into a python REPL?� I adapted the
> doc/core/examples/stdin.py code below to drop into the �code� stdlib
Use twisted.conch.manhole.ManholeInterpreter. Here's its docstring:
class ManholeInterpreter(code.InteractiveInterpreter):
"""Interactive Interpreter with special output and Deferred support.
Aside from the features provided by L{code.InteractiveInterpreter}, this
class captures sys.stdout output and redirects it to the appropriate
location (the Manhole protocol instance). It also treats Deferreds
which reach the top-level specially: each is formatted to the user with
a unique identifier and a new callback and errback added to it, each of
which will format the unique identifier and the result with which the
Deferred fires and then pass it on to the next participant in the
callback chain.
"""
-Andrew.
More information about the Twisted-Python
mailing list