Skip to content

Commit 6347de1

Browse files
committed
asyncio: Clean up code a bit.
1 parent dab2a22 commit 6347de1

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

asyncio/asyncio.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
IO_WRITE = 2
1212

1313

14-
def coroutine(f):
15-
return f
16-
17-
1814
class EventLoop:
1915

2016
def __init__(self):
@@ -31,20 +27,16 @@ def call_later(self, delay, callback, *args):
3127
self.call_at(self.time() + delay, callback, *args)
3228

3329
def call_at(self, time, callback, *args):
34-
# self.q.append((callback, args))
35-
# self.cnt is workaround per heapq docs
30+
# Including self.cnt is a workaround per heapq docs
3631
log.debug("Scheduling %s", (time, self.cnt, callback, args))
3732
heapq.heappush(self.q, (time, self.cnt, callback, args))
3833
# print(self.q)
3934
self.cnt += 1
4035

41-
# def run_forever(self):
42-
# while self.q:
43-
# c = self.q.pop(0)
44-
# c[0](*c[1])
45-
4636
def wait(self, delay):
47-
# print("Sleeping for:", delay)
37+
# Default wait implementation, to be overriden in subclasses
38+
# with IO scheduling
39+
log.debug("Sleeping for: %s", delay)
4840
time.sleep(delay)
4941

5042
def run_forever(self):
@@ -91,7 +83,6 @@ def run_forever(self):
9183
except StopIteration as e:
9284
log.debug("Gen finished: %s", cb)
9385
continue
94-
#self.q.append(c)
9586
self.call_later(delay, cb, *args)
9687

9788
def run_until_complete(self, coro):
@@ -109,6 +100,7 @@ def run_until_complete(self, coro):
109100
def close(self):
110101
pass
111102

103+
112104
import select
113105

114106
class EpollEventLoop(EventLoop):
@@ -176,6 +168,9 @@ def __init__(self, op, obj):
176168
def get_event_loop():
177169
return EpollEventLoop()
178170

171+
def coroutine(f):
172+
return f
173+
179174
def async(coro):
180175
# We don't have Task bloat, so op is null
181176
return coro

0 commit comments

Comments
 (0)