python/cpython · error · TypeError
coroutines cannot be used with {method}()
Error message
coroutines cannot be used with {method}() What it means
Error "coroutines cannot be used with {method}()" thrown in python/cpython.
Source
Thrown at Lib/asyncio/base_events.py:845
order in which they are registered. Each callback will be
called exactly once.
Any positional arguments after the callback will be passed to
the callback when it is called.
"""
self._check_closed()
if self._debug:
self._check_thread()
self._check_callback(callback, 'call_soon')
handle = self._call_soon(callback, args, context)
if handle._source_traceback:
del handle._source_traceback[-1]
return handle
def _check_callback(self, callback, method):
if (coroutines.iscoroutine(callback) or
inspect.iscoroutinefunction(callback)):
raise TypeError(
f"coroutines cannot be used with {method}()")
if not callable(callback):
raise TypeError(
f'a callable object was expected by {method}(), '
f'got {callback!r}')
def _call_soon(self, callback, args, context):
handle = events.Handle(callback, args, self, context)
if handle._source_traceback:
del handle._source_traceback[-1]
self._ready.append(handle)
return handle
def _check_thread(self):
"""Check that the current thread is the thread running the event loop.
Non-thread-safe methods of this class make this assumption and will
likely behave incorrectly when the assumption is violated.View on GitHub (pinned to bc6749cc3b)
Solutions
- Pass a plain function/callback, not a coroutine function; wrap coroutines with loop.create_task() or ensure_future() if you need async work.
- If you must call async code from the callback, schedule it: lambda: loop.create_task(coro()).
When it happens
Trigger: Raised when a coroutine object is passed to call_soon/call_later/call_at instead of a plain callback.
Common situations: See trigger scenarios.
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/2c5036492fa229db.
Report an issue: GitHub.