kopia lustrzana https://github.com/micropython/micropython-lib
asyncio_slow: Implement loop.stop().
rodzic
8d1ae59f3a
commit
30a0586732
|
@ -6,9 +6,10 @@ log = logging.getLogger("asyncio")
|
||||||
|
|
||||||
|
|
||||||
# Workaround for not being able to subclass builtin types
|
# Workaround for not being able to subclass builtin types
|
||||||
DoneException = AssertionError
|
class LoopStop(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class InvalidStateError:
|
class InvalidStateError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Object not matching any other object
|
# Object not matching any other object
|
||||||
|
@ -32,21 +33,23 @@ class EventLoop:
|
||||||
def run_forever(self):
|
def run_forever(self):
|
||||||
while self.q:
|
while self.q:
|
||||||
c = self.q.pop(0)
|
c = self.q.pop(0)
|
||||||
c[0](*c[1])
|
try:
|
||||||
|
c[0](*c[1])
|
||||||
|
except LoopStop:
|
||||||
|
return
|
||||||
# I mean, forever
|
# I mean, forever
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
def run_until_complete(self, coro):
|
def stop(self):
|
||||||
def _cb(val):
|
def _cb():
|
||||||
raise DoneException
|
raise LoopStop
|
||||||
|
self.call_soon(_cb)
|
||||||
|
|
||||||
|
def run_until_complete(self, coro):
|
||||||
t = async(coro)
|
t = async(coro)
|
||||||
t.add_done_callback(_cb)
|
t.add_done_callback(lambda a: self.stop())
|
||||||
try:
|
self.run_forever()
|
||||||
self.run_forever()
|
|
||||||
except DoneException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
Ładowanie…
Reference in New Issue