kopia lustrzana https://github.com/micropython/micropython-lib
uasyncio.core: Add additional debug output control.
__debug__ isn't flexible enough, if you don't disable it, there's huge memory allocation.pull/120/head
rodzic
02a6625a00
commit
b3c2d0f51e
|
@ -6,6 +6,8 @@ import uheapq as heapq
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
DEBUG = 0
|
||||||
|
|
||||||
log = logging.getLogger("asyncio")
|
log = logging.getLogger("asyncio")
|
||||||
|
|
||||||
type_gen = type((lambda: (yield))())
|
type_gen = type((lambda: (yield))())
|
||||||
|
@ -33,7 +35,7 @@ class EventLoop:
|
||||||
self.call_at_(time.ticks_add(self.time(), delay), callback, args)
|
self.call_at_(time.ticks_add(self.time(), delay), callback, args)
|
||||||
|
|
||||||
def call_at(self, time, callback, *args):
|
def call_at(self, time, callback, *args):
|
||||||
if __debug__:
|
if __debug__ and DEBUG:
|
||||||
log.debug("Scheduling %s", (time, callback, args))
|
log.debug("Scheduling %s", (time, callback, args))
|
||||||
heapq.heappush(self.q, (time, callback, args), True)
|
heapq.heappush(self.q, (time, callback, args), True)
|
||||||
|
|
||||||
|
@ -45,7 +47,7 @@ class EventLoop:
|
||||||
def wait(self, delay):
|
def wait(self, delay):
|
||||||
# Default wait implementation, to be overriden in subclasses
|
# Default wait implementation, to be overriden in subclasses
|
||||||
# with IO scheduling
|
# with IO scheduling
|
||||||
if __debug__:
|
if __debug__ and DEBUG:
|
||||||
log.debug("Sleeping for: %s", delay)
|
log.debug("Sleeping for: %s", delay)
|
||||||
time.sleep_ms(delay)
|
time.sleep_ms(delay)
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ class EventLoop:
|
||||||
while True:
|
while True:
|
||||||
if self.q:
|
if self.q:
|
||||||
t, cb, args = heapq.heappop(self.q, True)
|
t, cb, args = heapq.heappop(self.q, True)
|
||||||
if __debug__:
|
if __debug__ and DEBUG:
|
||||||
log.debug("Next coroutine to run: %s", (t, cb, args))
|
log.debug("Next coroutine to run: %s", (t, cb, args))
|
||||||
# __main__.mem_info()
|
# __main__.mem_info()
|
||||||
tnow = self.time()
|
tnow = self.time()
|
||||||
|
@ -69,13 +71,13 @@ class EventLoop:
|
||||||
else:
|
else:
|
||||||
delay = 0
|
delay = 0
|
||||||
try:
|
try:
|
||||||
if __debug__:
|
if __debug__ and DEBUG:
|
||||||
log.debug("Coroutine %s send args: %s", cb, args)
|
log.debug("Coroutine %s send args: %s", cb, args)
|
||||||
if args == ():
|
if args == ():
|
||||||
ret = next(cb)
|
ret = next(cb)
|
||||||
else:
|
else:
|
||||||
ret = cb.send(*args)
|
ret = cb.send(*args)
|
||||||
if __debug__:
|
if __debug__ and DEBUG:
|
||||||
log.debug("Coroutine %s yield result: %s", cb, ret)
|
log.debug("Coroutine %s yield result: %s", cb, ret)
|
||||||
if isinstance(ret, SysCall1):
|
if isinstance(ret, SysCall1):
|
||||||
arg = ret.arg
|
arg = ret.arg
|
||||||
|
@ -108,7 +110,7 @@ class EventLoop:
|
||||||
else:
|
else:
|
||||||
assert False, "Unsupported coroutine yield value: %r (of type %r)" % (ret, type(ret))
|
assert False, "Unsupported coroutine yield value: %r (of type %r)" % (ret, type(ret))
|
||||||
except StopIteration as e:
|
except StopIteration as e:
|
||||||
if __debug__:
|
if __debug__ and DEBUG:
|
||||||
log.debug("Coroutine finished: %s", cb)
|
log.debug("Coroutine finished: %s", cb)
|
||||||
continue
|
continue
|
||||||
self.call_later_ms_(delay, cb, args)
|
self.call_later_ms_(delay, cb, args)
|
||||||
|
|
Ładowanie…
Reference in New Issue