python/cpython · error · TypeError
executor must be ThreadPoolExecutor instance
Error message
executor must be ThreadPoolExecutor instance
What it means
Error "executor must be ThreadPoolExecutor instance" thrown in python/cpython.
Source
Thrown at Lib/asyncio/base_events.py:908
def run_in_executor(self, executor, func, *args):
self._check_closed()
if self._debug:
self._check_callback(func, 'run_in_executor')
if executor is None:
executor = self._default_executor
# Only check when the default executor is being used
self._check_default_executor()
if executor is None:
executor = concurrent.futures.ThreadPoolExecutor(
thread_name_prefix='asyncio'
)
self._default_executor = executor
return futures.wrap_future(
executor.submit(func, *args), loop=self)
def set_default_executor(self, executor):
if not isinstance(executor, concurrent.futures.ThreadPoolExecutor):
raise TypeError('executor must be ThreadPoolExecutor instance')
self._default_executor = executor
def _getaddrinfo_debug(self, host, port, family, type, proto, flags):
msg = [f"{host}:{port!r}"]
if family:
msg.append(f'family={family!r}')
if type:
msg.append(f'type={type!r}')
if proto:
msg.append(f'proto={proto!r}')
if flags:
msg.append(f'flags={flags!r}')
msg = ', '.join(msg)
logger.debug('Get address info %s', msg)
t0 = self.time()
addrinfo = socket.getaddrinfo(host, port, family, type, proto, flags)
dt = self.time() - t0View on GitHub (pinned to bc6749cc3b)
Solutions
- Pass a concurrent.futures.ThreadPoolExecutor instance to loop.set_default_executor(); ProcessPoolExecutor is not supported as the default executor.
When it happens
Trigger: Raised when set_default_executor() is given an executor that is not a ThreadPoolExecutor.
Common situations: See trigger scenarios.
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/2f464181663a534c.
Report an issue: GitHub.