No subject
Fri Jan 7 07:23:30 MST 2011
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