python/cpython · error · RuntimeError

Executor shutdown has been called

Error message

Executor shutdown has been called

What it means

Error "Executor shutdown has been called" thrown in python/cpython.

Source

Thrown at Lib/asyncio/base_events.py:560

        """Write a byte to self-pipe, to wake up the event loop.

        This may be called from a different thread.

        The subclass is responsible for implementing the self-pipe.
        """
        raise NotImplementedError

    def _process_events(self, event_list):
        """Process selector events."""
        raise NotImplementedError

    def _check_closed(self):
        if self._closed:
            raise RuntimeError('Event loop is closed')

    def _check_default_executor(self):
        if self._executor_shutdown_called:
            raise RuntimeError('Executor shutdown has been called')

    def _asyncgen_finalizer_hook(self, agen):
        self._asyncgens.discard(agen)
        if not self.is_closed():
            self.call_soon_threadsafe(self.create_task, agen.aclose())

    def _asyncgen_firstiter_hook(self, agen):
        if self._asyncgens_shutdown_called:
            warnings.warn(
                f"asynchronous generator {agen!r} was scheduled after "
                f"loop.shutdown_asyncgens() call",
                ResourceWarning, source=self)

        self._asyncgens.add(agen)

    async def shutdown_asyncgens(self):
        """Shutdown all active asynchronous generators."""
        self._asyncgens_shutdown_called = True

View on GitHub (pinned to bc6749cc3b)

Solutions

  1. Do not call run_in_executor() after loop.shutdown_default_executor(); reorder shutdown to after all executor work completes.
  2. Await pending executor futures before shutting down the loop.

When it happens

Trigger: Raised when submitting work to an executor after shutdown has been requested.

Common situations: See trigger scenarios.


AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14). Data as JSON: /api/errors/c250495e4ebc6deb. Report an issue: GitHub.