[Twisted-Python] Twisted and ipython
Alessandro Dentella
sandro at e-den.it
Sun Jan 16 16:12:37 MST 2011
thanks Jean-Paul for the hints,
On Sun, Jan 16, 2011 at 12:50:05AM -0000, exarkun at twistedmatrix.com wrote:
> On 13 Jan, 11:43 pm, sandro at e-den.it wrote:
> >thanks,
> >
> >short abstact: manhole is very good, thanks. But I'd need to add
> >readline to
> >make it usable and I'd need tab-completion too.
>
> If by "add readline" you mean handle input using the stdlib readline
> module, you can't really do this (or, I'm sure you can, but it would
> involve a ton of coding). If you only mean "have some commonly useful
> line editing features" then you have at least a couple options:
Well, in fact I intended mainly up/down arrows *and* tab-completion, like
ipython have.
> * invective includes a fully unit-tested line input widget (for the
> insults widget library). This really belongs somewhere other than
> invective, it'd be nice if someone pushed it back into Twisted.
> However, you can find invective at
> svn://svn.twistedmatrix.com/svn/Twisted/sandbox/exarkun/invective/trunk
> until that happens.
>
> * urwid supports Twisted and has lots of fancy things, including an
> input editing widget.
>From what you say I don't know if completion is something I'd
get with invective of urwid.
> Also, we really should get rid of twisted.manhole, because these days
> manhole is supposed to refer to the stuff in twisted.conch. I'm not
> sure if you found the latter, but from the warning you got about
> twisted.protocols.telnet it seems like you may have only found the
> former.
I was able to use only manhole.telnet. I wan't able to understand how to
make twisted.protocols.telnet work in the same way and was not able to fine
a demo snippet (more for completeness that else I'm still interested in
this).
On the other hand I managed to use ipython and twisted as I wanted and
everitying is working like a charm (but I still have a question that I'll
leave for next chapter).
Twisted in a thread - working setup
-----------------------------------
Following a hint in the ipython ml I started a second thread for twisted and
I'm using blockingcallFromThread to dispatch commands to the reactor:
proto = Domotik()
SerialPort(proto, o.opts['device'], reactor, baudrate=int(o.opts['baudrate']))
rit = twistedutil.ReactorInThread()
rit.setDaemon(True)
rit.start()
q = Quadro(proto, discover=False)
proto.quadro = q
q.discover_modules()
This works exactly as I wanted. I can interact with 'q' that represents a
collection of electric modules on the serial bus
The unresolved doubt
--------------------------------
What I can't understand is why I can't put "q.discover_modules()" inside
callWhenRunning() command: if I do that it just blocks at the first
iteration of the 'for' loop.
reactor.callWhenRunning( start_command, proto)
def start_command(proto):
q.discover_modules()
class Quadro(object):
def __init__(self, proto):
self.proto = proto
self.modules = []
def discover_modules(self):
"""send a request to the serial bus to understand which electric
modules are present"""
for x in range(10):
blockingCallFromThread(reactor.callLater, 1 + x/5.0, self.proto.ask_status, x)
thanks
sandro
*:-)
--
Sandro Dentella *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.org SQLkit home page - PyGTK/python/sqlalchemy
More information about the Twisted-Python
mailing list