Skip to content

Commit 8711a45

Browse files
author
Paul Sokolovsky
committed
asyncio_slow: Implement loop.stop().
1 parent 3a639ce commit 8711a45

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

asyncio_slow/asyncio_slow.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77

88
# Workaround for not being able to subclass builtin types
9-
DoneException = AssertionError
9+
class LoopStop(Exception):
10+
pass
1011

11-
class InvalidStateError:
12+
class InvalidStateError(Exception):
1213
pass
1314

1415
# Object not matching any other object
@@ -32,21 +33,23 @@ def _delayed(c, args, delay):
3233
def run_forever(self):
3334
while self.q:
3435
c = self.q.pop(0)
35-
c[0](*c[1])
36+
try:
37+
c[0](*c[1])
38+
except LoopStop:
39+
return
3640
# I mean, forever
3741
while True:
3842
time.sleep(1)
3943

40-
def run_until_complete(self, coro):
41-
def _cb(val):
42-
raise DoneException
44+
def stop(self):
45+
def _cb():
46+
raise LoopStop
47+
self.call_soon(_cb)
4348

49+
def run_until_complete(self, coro):
4450
t = async(coro)
45-
t.add_done_callback(_cb)
46-
try:
47-
self.run_forever()
48-
except DoneException:
49-
pass
51+
t.add_done_callback(lambda a: self.stop())
52+
self.run_forever()
5053

5154
def close(self):
5255
pass

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy