Message149452
Now that I think of it maybe some kind of wrapper would still be necessary.
As of right now, we'd do something like this.
At the core we would have:
import asyncore, asynchat, sched
# global
scheduler = sched.scheduler()
while 1:
asyncore.loop(timeout=1.0, count=1) # count=1 makes loop() return after 1 loop
scheduler.run(blocking=False)
Then, every dispatcher can define a scheduled function of its own:
class Client(asynchat.async_chat):
# an already connected client
# (the "connector" code is not included in this example)
def __init__(self, *args, **kwargs):
asynchat.async_chat.__init__(self, *args, **kwargs)
self.set_terminator("\r\n")
self.set_timeout()
def set_timeout(self):
self.timeout = scheduler.enter(30, 0, self.handle_timeout)
def reset_timeout(self):
scheduler.cancel(self.timeout)
self.set_timeout()
def found_terminator(self):
scheduler.cancel(self.timeout)
self.timeout = scheduler.enter(30, 0, self.handle_timeout)
# do something with the received data...
def handle_timeout(self):
self.push("400 connection timed out\r\n")
self.close()
def close(self):
scheduler.cancel(self.timeout)
asynchat.async_chat.close(self) |
|
Date |
User |
Action |
Args |
2011-12-14 14:24:38 | giampaolo.rodola | set | recipients:
+ giampaolo.rodola, gvanrossum, akuchling, facundobatista, jafo, josiahcarlson, tseaver, mark.dickinson, pitrou, forest, kevinwatters, djarb, stutzbach, markb, r.david.murray, intgr, mcdonc, j1m |
2011-12-14 14:24:38 | giampaolo.rodola | set | messageid: <1323872678.16.0.0110370948978.issue1641@psf.upfronthosting.co.za> |
2011-12-14 14:24:37 | giampaolo.rodola | link | issue1641 messages |
2011-12-14 14:24:37 | giampaolo.rodola | create | |
|