Skip to content

Commit 25bcef1

Browse files
author
Paul Sokolovsky
committed
asyncio: Recover eventloop's ability to work with callbacks.
Actually, coroutine support for call_soon() is a hack, in big asyncio coroutine should be wrapped in Task object.
1 parent 78fef25 commit 25bcef1

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

asyncio/asyncio.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,20 @@ def run_forever(self):
4646
delay = t - tnow
4747
if delay > 0:
4848
self.wait(delay)
49-
delay = 0
50-
try:
51-
ret = next(cb)
52-
# print("ret:", ret)
53-
if isinstance(ret, Sleep):
54-
delay = ret.args[0]
55-
except StopIteration as e:
56-
print(c, "finished")
57-
continue
58-
#self.q.append(c)
59-
self.call_later(delay, cb, *args)
49+
if callable(cb):
50+
cb(*args)
51+
else:
52+
delay = 0
53+
try:
54+
ret = next(cb)
55+
# print("ret:", ret)
56+
if isinstance(ret, Sleep):
57+
delay = ret.args[0]
58+
except StopIteration as e:
59+
print(c, "finished")
60+
continue
61+
#self.q.append(c)
62+
self.call_later(delay, cb, *args)
6063

6164
def run_until_complete(self, coro):
6265
val = None

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