Skip to content

Commit b3c2d0f

Browse files
committed
uasyncio.core: Add additional debug output control.
__debug__ isn't flexible enough, if you don't disable it, there's huge memory allocation.
1 parent 02a6625 commit b3c2d0f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

uasyncio.core/uasyncio/core.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import logging
77

88

9+
DEBUG = 0
10+
911
log = logging.getLogger("asyncio")
1012

1113
type_gen = type((lambda: (yield))())
@@ -33,7 +35,7 @@ def call_later_ms_(self, delay, callback, args=()):
3335
self.call_at_(time.ticks_add(self.time(), delay), callback, args)
3436

3537
def call_at(self, time, callback, *args):
36-
if __debug__:
38+
if __debug__ and DEBUG:
3739
log.debug("Scheduling %s", (time, callback, args))
3840
heapq.heappush(self.q, (time, callback, args), True)
3941

@@ -45,15 +47,15 @@ def call_at_(self, time, callback, args=()):
4547
def wait(self, delay):
4648
# Default wait implementation, to be overriden in subclasses
4749
# with IO scheduling
48-
if __debug__:
50+
if __debug__ and DEBUG:
4951
log.debug("Sleeping for: %s", delay)
5052
time.sleep_ms(delay)
5153

5254
def run_forever(self):
5355
while True:
5456
if self.q:
5557
t, cb, args = heapq.heappop(self.q, True)
56-
if __debug__:
58+
if __debug__ and DEBUG:
5759
log.debug("Next coroutine to run: %s", (t, cb, args))
5860
# __main__.mem_info()
5961
tnow = self.time()
@@ -69,13 +71,13 @@ def run_forever(self):
6971
else:
7072
delay = 0
7173
try:
72-
if __debug__:
74+
if __debug__ and DEBUG:
7375
log.debug("Coroutine %s send args: %s", cb, args)
7476
if args == ():
7577
ret = next(cb)
7678
else:
7779
ret = cb.send(*args)
78-
if __debug__:
80+
if __debug__ and DEBUG:
7981
log.debug("Coroutine %s yield result: %s", cb, ret)
8082
if isinstance(ret, SysCall1):
8183
arg = ret.arg
@@ -108,7 +110,7 @@ def run_forever(self):
108110
else:
109111
assert False, "Unsupported coroutine yield value: %r (of type %r)" % (ret, type(ret))
110112
except StopIteration as e:
111-
if __debug__:
113+
if __debug__ and DEBUG:
112114
log.debug("Coroutine finished: %s", cb)
113115
continue
114116
self.call_later_ms_(delay, cb, args)

0 commit comments

Comments
 (0)