asyncio: Clean up code a bit.

pull/11/head
Paul Sokolovsky 2014-05-02 21:10:21 +03:00
rodzic bce6c1cadf
commit 4071bb5e74
1 zmienionych plików z 8 dodań i 13 usunięć

Wyświetl plik

@ -11,10 +11,6 @@ IO_READ = 1
IO_WRITE = 2 IO_WRITE = 2
def coroutine(f):
return f
class EventLoop: class EventLoop:
def __init__(self): def __init__(self):
@ -31,20 +27,16 @@ class EventLoop:
self.call_at(self.time() + delay, callback, *args) self.call_at(self.time() + delay, callback, *args)
def call_at(self, time, callback, *args): def call_at(self, time, callback, *args):
# self.q.append((callback, args)) # Including self.cnt is a workaround per heapq docs
# self.cnt is workaround per heapq docs
log.debug("Scheduling %s", (time, self.cnt, callback, args)) log.debug("Scheduling %s", (time, self.cnt, callback, args))
heapq.heappush(self.q, (time, self.cnt, callback, args)) heapq.heappush(self.q, (time, self.cnt, callback, args))
# print(self.q) # print(self.q)
self.cnt += 1 self.cnt += 1
# def run_forever(self):
# while self.q:
# c = self.q.pop(0)
# c[0](*c[1])
def wait(self, delay): def wait(self, delay):
# print("Sleeping for:", delay) # Default wait implementation, to be overriden in subclasses
# with IO scheduling
log.debug("Sleeping for: %s", delay)
time.sleep(delay) time.sleep(delay)
def run_forever(self): def run_forever(self):
@ -91,7 +83,6 @@ class EventLoop:
except StopIteration as e: except StopIteration as e:
log.debug("Gen finished: %s", cb) log.debug("Gen finished: %s", cb)
continue continue
#self.q.append(c)
self.call_later(delay, cb, *args) self.call_later(delay, cb, *args)
def run_until_complete(self, coro): def run_until_complete(self, coro):
@ -109,6 +100,7 @@ class EventLoop:
def close(self): def close(self):
pass pass
import select import select
class EpollEventLoop(EventLoop): class EpollEventLoop(EventLoop):
@ -176,6 +168,9 @@ class IODone(SysCall):
def get_event_loop(): def get_event_loop():
return EpollEventLoop() return EpollEventLoop()
def coroutine(f):
return f
def async(coro): def async(coro):
# We don't have Task bloat, so op is null # We don't have Task bloat, so op is null
return coro return coro