{"record":{"id":"fa70adaac4734126","repo":"python/cpython","slug":"non-thread-safe-operation-invoked-on-an-event-loop","errorCode":null,"errorMessage":"Non-thread-safe operation invoked on an event loop other than the current one","messagePattern":"Non-thread-safe operation invoked on an event loop other than the current one","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":872,"sourceCode":"        if handle._source_traceback:\n            del handle._source_traceback[-1]\n        self._ready.append(handle)\n        return handle\n\n    def _check_thread(self):\n        \"\"\"Check that the current thread is the thread running the event loop.\n\n        Non-thread-safe methods of this class make this assumption and will\n        likely behave incorrectly when the assumption is violated.\n\n        Should only be called when (self._debug == True).  The caller is\n        responsible for checking this condition for performance reasons.\n        \"\"\"\n        if self._thread_id is None:\n            return\n        thread_id = threading.get_ident()\n        if thread_id != self._thread_id:\n            raise RuntimeError(\n                \"Non-thread-safe operation invoked on an event loop other \"\n                \"than the current one\")\n\n    def call_soon_threadsafe(self, callback, *args, context=None):\n        \"\"\"Like call_soon(), but thread-safe.\"\"\"\n        self._check_closed()\n        if self._debug:\n            self._check_callback(callback, 'call_soon_threadsafe')\n        handle = events._ThreadSafeHandle(callback, args, self, context)\n        self._ready.append(handle)\n        if handle._source_traceback:\n            del handle._source_traceback[-1]\n        if handle._source_traceback:\n            del handle._source_traceback[-1]\n        self._write_to_self()\n        return handle\n\n    def run_in_executor(self, executor, func, *args):","sourceCodeStart":854,"sourceCodeEnd":890,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/base_events.py#L854-L890","documentation":"Error \"Non-thread-safe operation invoked on an event loop other than the current one\" thrown in python/cpython.","triggerScenarios":"Raised when a non-thread-safe loop operation is invoked from a thread other than the loop's thread.","commonSituations":"See trigger scenarios.","solutions":["From another thread, use loop.call_soon_threadsafe() instead of call_soon()/call_later().","Use asyncio.run_coroutine_threadsafe(coro, loop) to submit coroutines from other threads."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}