This has been driving me crazy for a while -- for some reason
reactor.stop() in the _error errback in example below raises
error.ReactorNotRunning. In order to stop the reactor, I have to do
reactor.callWhenRunning(reactor.stop) (or I did reactor.callLater(0,
...) until I discovered callWhenRunning).
In the example, I bind to a low port to make sure error is triggered.
#!/usr/local/bin/python3
from twisted.internet import reactor, defer, protocol
from twisted.internet.protocol import Factory
…
[View More]from twisted.internet.endpoints import TCP4ServerEndpoint
def _port(port):
print('got', port)
def _error(err):
print('got err', err)
print('is reactor running?', reactor.running)
print('is reactor running?', (lambda: reactor.running)())
reactor.stop()
# reactor.callWhenRunning(reactor.stop)
d = TCP4ServerEndpoint(reactor, 123).listen(Factory())
d.addCallback(_port)
d.addErrback(_error)
d.addErrback(print)
reactor.run()
OTOH, in the following example reactor.stop() is stoppig the reactor
properly:
#!/usr/local/bin/python3
from twisted.internet import reactor, defer
def cb(res):
print('running?', reactor.running)
if res == 'bar':
raise Exception()
reactor.stop()
def eb(err):
print('running?', reactor.running)
print(err)
reactor.stop()
d = defer.Deferred()
d.addCallback(cb)
d.addErrback(eb)
#reactor.callWhenRunning(d.callback, 'foo')
reactor.callWhenRunning(d.callback, 'bar')
reactor.run()
Any ideas?
[View Less]
Hello, world!
I'm very happy to be using Twisted again -- after a break of about 20
years! In ol' days I did mailing lists in Twisted, implemented Dovecot
AUTH protocol in Twisted and a lot more. Mostly it was mail related. A
lot have been forgotten and have to be re-discovered.
A couple of words about use-case: I was curious about what could be
achieved using the filtering facility in the OpenSMTPD MTA. The filters
are programs which are executed by the daemon, and some data is
…
[View More]exchanged on stdin/stdout using non-blocking fashion. More at
https://man.openbsd.org/smtpd-filters
I tried getting Python asyncio to work at first, even using aioconsole
package, but I kept hitting something which made the thing break after
handshake exchange. This evening I did a rewrite in Twisted, it took me
a couple of hours, but the was running on the first try!
Thanks for all the fish!
-- Kirill
[View Less]
I'm playing with PB, and it's booth cool and somewhat confusing. So I
have some remote_* methods, e.g.
def remote_ping(self):
return 'pong'
def remote_run(self):
d = Deferred()
d.AddCallback(self.got_result)
# return d # <- magic here when deferred is returned?
def got_result(self, res)
return res
When I do callRemote('ping') and execute callback, I am getting 'pong'
as a result. However, when I do callRemote('run'), it returns a
deferred which returns None, which is …
[View More]expected, as remote_run()
doesn't have any result yet.
However, if I return deferred ("d") from remote_run, then callRemote('run') gives me
the result. Is it some expected magic going on when remote_ method returns a deferred?
[View Less]