I have a weird situation when running the below code in debug mode in Pycharm.
It works great in run mode or in debug mode when using default policy but the default (Proactor) policy breaks another part of the application (see below)
Important: I am using WindowsSelectorEventLoopPolicy as i need to use loop.add_reader()/loop.add_writer() to the loop for sockets, and as per https://github.com/tornadoweb/tornado/issues/2608#issuecomment-619524992 I understood (and tested with success) that adding/removing readers/writers works with "Selector" event loop, but not with "Proactor" event loop, where I was getting NotImplementedErrors.
Sample code, reduced to the bare minimium :
import asyncio
import os
import sys
if sys.version_info >= (3, 8) and os.name == "nt":
# this is required to work with loop.add_reader & co
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# this solves the current issue but break add_reader/add_writer
# asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
async def main() -> None:
print("foo")
if __name__ == '__main__':
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
Result in "run" mode :
foo
Result in "debug" mode :
Exception in callback <Task pending name='Task-1'
coro=<main() running at C:\...\a.py:21>
cb=[_run_until_complete_cb() at C:\... Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py:181]>()
handle: <Handle <Task pending name='Task-1'
coro=<main() running at C:\...\a.py:21>
cb=[_run_until_complete_cb() at C:\... Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py:181]>()>
Traceback (most recent call last):
File "C:\... Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\asyncio\events.py", line 84, in _run
self._context.run(self._callback, *self._args)
TypeError: 'Task' object is not callable
I am using python 3.11 on Windows from windows store, and PyCharm 2025.1.2 Build #PY-251.26094.141, built on June 10 2025, if it has any importance.
The following helped me with a TypeError: 'Task' object is not callable error in PyCharm when running the debugger. I was using the scrapy library and it behaved in the same way as your error while debugging, but I suspect that you are seeing a similar issue with the asyncio library.
Press Shift twice to open the search window
From the main bar select Actions
Type in Registry and select Registry...
From here scroll down to python.debug.asyncio.repl and make sure the Value column is deselected
This is taken from the following answer: Cannot debug script with trio_asyncio in PyCharm
I have just run in to the same problem with PyCharm 2025.2. After digging a little bit, I made core plugin file changes to suppress this part and side effects. Debugging still works anyway.
C:\Program Files\JetBrains\PyCharm 2025.2\plugins\python\helpers-pro\pydevd_asyncio\pydevd_nest_asyncio.py:34
if IS_ASYNCIO_DEBUGGER_ENV:
change to
if False:
(use admin permission to perform this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With