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.