11
11
IO_WRITE = 2
12
12
13
13
14
- def coroutine (f ):
15
- return f
16
-
17
-
18
14
class EventLoop :
19
15
20
16
def __init__ (self ):
@@ -31,20 +27,16 @@ def call_later(self, delay, callback, *args):
31
27
self .call_at (self .time () + delay , callback , * args )
32
28
33
29
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
36
31
log .debug ("Scheduling %s" , (time , self .cnt , callback , args ))
37
32
heapq .heappush (self .q , (time , self .cnt , callback , args ))
38
33
# print(self.q)
39
34
self .cnt += 1
40
35
41
- # def run_forever(self):
42
- # while self.q:
43
- # c = self.q.pop(0)
44
- # c[0](*c[1])
45
-
46
36
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 )
48
40
time .sleep (delay )
49
41
50
42
def run_forever (self ):
@@ -91,7 +83,6 @@ def run_forever(self):
91
83
except StopIteration as e :
92
84
log .debug ("Gen finished: %s" , cb )
93
85
continue
94
- #self.q.append(c)
95
86
self .call_later (delay , cb , * args )
96
87
97
88
def run_until_complete (self , coro ):
@@ -109,6 +100,7 @@ def run_until_complete(self, coro):
109
100
def close (self ):
110
101
pass
111
102
103
+
112
104
import select
113
105
114
106
class EpollEventLoop (EventLoop ):
@@ -176,6 +168,9 @@ def __init__(self, op, obj):
176
168
def get_event_loop ():
177
169
return EpollEventLoop ()
178
170
171
+ def coroutine (f ):
172
+ return f
173
+
179
174
def async (coro ):
180
175
# We don't have Task bloat, so op is null
181
176
return coro
0 commit comments