kopia lustrzana https://github.com/micropython/micropython-lib
uasyncio.core: Don't pass any callback args to add_reader/add_writer.
Instead, capture all needed param in closure. Due do bug in MicroPython's handling of default args to lambdas, helper function is used.pull/63/head
rodzic
ff27e3c8ba
commit
460dd59b16
|
@ -44,6 +44,12 @@ class EventLoop:
|
||||||
log.debug("Sleeping for: %s", delay)
|
log.debug("Sleeping for: %s", delay)
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
|
||||||
|
# Workaround bug for in uPy - default args for lambda's are not supported
|
||||||
|
def lambda_helper(self, cb):
|
||||||
|
def lmb(cb=cb):
|
||||||
|
self.call_soon(cb)
|
||||||
|
return lmb
|
||||||
|
|
||||||
def run_forever(self):
|
def run_forever(self):
|
||||||
while True:
|
while True:
|
||||||
if self.q:
|
if self.q:
|
||||||
|
@ -78,10 +84,12 @@ class EventLoop:
|
||||||
elif isinstance(ret, IORead):
|
elif isinstance(ret, IORead):
|
||||||
# self.add_reader(ret.obj.fileno(), lambda self, c, f: self.call_soon(c, f), self, cb, ret.obj)
|
# self.add_reader(ret.obj.fileno(), lambda self, c, f: self.call_soon(c, f), self, cb, ret.obj)
|
||||||
# self.add_reader(ret.obj.fileno(), lambda c, f: self.call_soon(c, f), cb, ret.obj)
|
# self.add_reader(ret.obj.fileno(), lambda c, f: self.call_soon(c, f), cb, ret.obj)
|
||||||
self.add_reader(arg.fileno(), lambda cb, f: self.call_soon(cb, f), cb, arg)
|
# self.add_reader(arg.fileno(), lambda cb: self.call_soon(cb), cb)
|
||||||
|
self.add_reader(arg.fileno(), self.lambda_helper(cb))
|
||||||
continue
|
continue
|
||||||
elif isinstance(ret, IOWrite):
|
elif isinstance(ret, IOWrite):
|
||||||
self.add_writer(arg.fileno(), lambda cb, f: self.call_soon(cb, f), cb, arg)
|
# self.add_writer(arg.fileno(), lambda cb: self.call_soon(cb), cb)
|
||||||
|
self.add_writer(arg.fileno(), self.lambda_helper(cb))
|
||||||
continue
|
continue
|
||||||
elif isinstance(ret, IOReadDone):
|
elif isinstance(ret, IOReadDone):
|
||||||
self.remove_reader(arg.fileno())
|
self.remove_reader(arg.fileno())
|
||||||
|
|
Ładowanie…
Reference in New Issue