{"record":{"id":"a6b9fff8b724c2d4","repo":"python/cpython","slug":"task-factory-must-be-a-callable-or-none","errorCode":null,"errorMessage":"task factory must be a callable or None","messagePattern":"task factory must be a callable or None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":497,"sourceCode":"            return task\n        finally:\n            # gh-128552: prevent a refcycle of\n            # task.exception().__traceback__->BaseEventLoop.create_task->task\n            del task\n\n    def set_task_factory(self, factory):\n        \"\"\"Set a task factory that will be used by loop.create_task().\n\n        If factory is None the default task factory will be set.\n\n        If factory is a callable, it should have a signature matching\n        '(loop, coro, **kwargs)', where 'loop' will be a reference to the\n        active event loop, 'coro' will be a coroutine object, and **kwargs\n        will be arbitrary keyword arguments that should be passed on to\n        Task.  The callable must return a Task.\n        \"\"\"\n        if factory is not None and not callable(factory):\n            raise TypeError('task factory must be a callable or None')\n        self._task_factory = factory\n\n    def get_task_factory(self):\n        \"\"\"Return a task factory, or None if the default one is in use.\"\"\"\n        return self._task_factory\n\n    def _make_socket_transport(self, sock, protocol, waiter=None, *,\n                               extra=None, server=None):\n        \"\"\"Create socket transport.\"\"\"\n        raise NotImplementedError\n\n    def _make_ssl_transport(\n            self, rawsock, protocol, sslcontext, waiter=None,\n            *, server_side=False, server_hostname=None,\n            extra=None, server=None,\n            ssl_handshake_timeout=None,\n            ssl_shutdown_timeout=None,\n            call_connection_made=True,","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/base_events.py#L479-L515","documentation":"Error \"task factory must be a callable or None\" thrown in python/cpython.","triggerScenarios":"Raised when loop.set_task_factory() is given a value that is neither callable nor None.","commonSituations":"See trigger scenarios.","solutions":["Pass a callable (e.g. a function or lambda) to loop.set_task_factory(), or None to reset it.","Ensure the factory signature is factory(loop, coro) and returns a Task."],"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-15T17:31:12.345Z"}