Skip to content

Commit f29be36

Browse files
committed
uasyncio: wait: Add workaround against heap alloc on empty iteration.
"for a in ():" unconditionally allocates heap so far, per micropython/micropython#2716 . So, test for empty result before iterating over it.
1 parent 9d5919d commit f29be36

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

uasyncio/uasyncio/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ def wait(self, delay):
6060
else:
6161
res = self.poller.poll(delay, 1)
6262
#log.debug("epoll result: %s", res)
63-
for fd, ev in res:
64-
cb = self.objmap[fd]
65-
if __debug__:
66-
log.debug("Calling IO callback: %r", cb)
67-
if isinstance(cb, tuple):
68-
cb[0](*cb[1])
69-
else:
70-
self.call_soon(cb)
63+
# Remove "if res" workaround after
64+
# https://github.com/micropython/micropython/issues/2716 fixed.
65+
if res:
66+
for fd, ev in res:
67+
cb = self.objmap[fd]
68+
if __debug__:
69+
log.debug("Calling IO callback: %r", cb)
70+
if isinstance(cb, tuple):
71+
cb[0](*cb[1])
72+
else:
73+
self.call_soon(cb)
7174

7275

7376
class StreamReader:

0 commit comments

Comments
 (0)