6
6
import logging
7
7
8
8
9
+ DEBUG = 0
10
+
9
11
log = logging .getLogger ("asyncio" )
10
12
11
13
type_gen = type ((lambda : (yield ))())
@@ -33,7 +35,7 @@ def call_later_ms_(self, delay, callback, args=()):
33
35
self .call_at_ (time .ticks_add (self .time (), delay ), callback , args )
34
36
35
37
def call_at (self , time , callback , * args ):
36
- if __debug__ :
38
+ if __debug__ and DEBUG :
37
39
log .debug ("Scheduling %s" , (time , callback , args ))
38
40
heapq .heappush (self .q , (time , callback , args ), True )
39
41
@@ -45,15 +47,15 @@ def call_at_(self, time, callback, args=()):
45
47
def wait (self , delay ):
46
48
# Default wait implementation, to be overriden in subclasses
47
49
# with IO scheduling
48
- if __debug__ :
50
+ if __debug__ and DEBUG :
49
51
log .debug ("Sleeping for: %s" , delay )
50
52
time .sleep_ms (delay )
51
53
52
54
def run_forever (self ):
53
55
while True :
54
56
if self .q :
55
57
t , cb , args = heapq .heappop (self .q , True )
56
- if __debug__ :
58
+ if __debug__ and DEBUG :
57
59
log .debug ("Next coroutine to run: %s" , (t , cb , args ))
58
60
# __main__.mem_info()
59
61
tnow = self .time ()
@@ -69,13 +71,13 @@ def run_forever(self):
69
71
else :
70
72
delay = 0
71
73
try :
72
- if __debug__ :
74
+ if __debug__ and DEBUG :
73
75
log .debug ("Coroutine %s send args: %s" , cb , args )
74
76
if args == ():
75
77
ret = next (cb )
76
78
else :
77
79
ret = cb .send (* args )
78
- if __debug__ :
80
+ if __debug__ and DEBUG :
79
81
log .debug ("Coroutine %s yield result: %s" , cb , ret )
80
82
if isinstance (ret , SysCall1 ):
81
83
arg = ret .arg
@@ -108,7 +110,7 @@ def run_forever(self):
108
110
else :
109
111
assert False , "Unsupported coroutine yield value: %r (of type %r)" % (ret , type (ret ))
110
112
except StopIteration as e :
111
- if __debug__ :
113
+ if __debug__ and DEBUG :
112
114
log .debug ("Coroutine finished: %s" , cb )
113
115
continue
114
116
self .call_later_ms_ (delay , cb , args )
0 commit comments