mirror of
https://github.com/python/cpython.git
synced 2025-07-31 07:04:42 +00:00
asyncio, Tulip issue 126: call_soon(), call_soon_threadsafe(), call_later(),
call_at() and run_in_executor() now raise a TypeError if the callback is a coroutine function.
This commit is contained in:
parent
1db2ba3a92
commit
a125497ea3
6 changed files with 39 additions and 13 deletions
|
@ -227,6 +227,8 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
|
||||
def call_at(self, when, callback, *args):
|
||||
"""Like call_later(), but uses an absolute time."""
|
||||
if tasks.iscoroutinefunction(callback):
|
||||
raise TypeError("coroutines cannot be used with call_at()")
|
||||
timer = events.TimerHandle(when, callback, args)
|
||||
heapq.heappush(self._scheduled, timer)
|
||||
return timer
|
||||
|
@ -241,6 +243,8 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
Any positional arguments after the callback will be passed to
|
||||
the callback when it is called.
|
||||
"""
|
||||
if tasks.iscoroutinefunction(callback):
|
||||
raise TypeError("coroutines cannot be used with call_soon()")
|
||||
handle = events.Handle(callback, args)
|
||||
self._ready.append(handle)
|
||||
return handle
|
||||
|
@ -252,6 +256,8 @@ class BaseEventLoop(events.AbstractEventLoop):
|
|||
return handle
|
||||
|
||||
def run_in_executor(self, executor, callback, *args):
|
||||
if tasks.iscoroutinefunction(callback):
|
||||
raise TypeError("coroutines cannot be used with run_in_executor()")
|
||||
if isinstance(callback, events.Handle):
|
||||
assert not args
|
||||
assert not isinstance(callback, events.TimerHandle)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue