From c60ff8125b3238fa01697922adb01f268a13cf0e Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 12 Dec 2015 00:12:19 +0200 Subject: [PATCH] uasyncio.core: Avoid wrapping coroutines to lambdas for add_reader/writer. add_reader/writer default behavior is to schedule "callback" on I/O completion via call_soon(), there's no need to have lambda for that. --- uasyncio.core/uasyncio/core.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/uasyncio.core/uasyncio/core.py b/uasyncio.core/uasyncio/core.py index 32efa042..6867a669 100644 --- a/uasyncio.core/uasyncio/core.py +++ b/uasyncio.core/uasyncio/core.py @@ -44,12 +44,6 @@ class EventLoop: log.debug("Sleeping for: %s", 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): while True: if self.q: @@ -85,11 +79,11 @@ class EventLoop: # 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(arg.fileno(), lambda cb: self.call_soon(cb), cb) - self.add_reader(arg.fileno(), self.lambda_helper(cb)) + self.add_reader(arg.fileno(), cb) continue elif isinstance(ret, IOWrite): # self.add_writer(arg.fileno(), lambda cb: self.call_soon(cb), cb) - self.add_writer(arg.fileno(), self.lambda_helper(cb)) + self.add_writer(arg.fileno(), cb) continue elif isinstance(ret, IOReadDone): self.remove_reader(arg.fileno())