Skip to content

_thread.get_ident returns a result with an exception set #128189

@AraHaan

Description

@AraHaan

Bug report

Bug description:

I am working on a python program that is async in nature and is carefully created using the C API as a C extension by using a generic awaitable object, Sadly, I had to implement what asyncio.run does manually due to it not liking how the awaitable object is designed because the only way to get the awaitable object the C api function returns is that it must first run the function in order for asyncio.run to then await the awaitable. However the 3.14 change to throw RuntimeError when get_event_loop() is called prior to asyncio.run actually creating it became a problem that I needed to solve with manually doing:

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(awaitable)
loop.close()

from the C code. Everything works well, Except when I Ctrl+C the program to terminate it and loop.close() returns NULL, I then PyErr_Print()'d it and see that:

Traceback (most recent call last):
  File "asyncio\base_events.py", line 707, in run_until_complete
  File "asyncio\base_events.py", line 678, in run_forever
  File "asyncio\base_events.py", line 1995, in _run_once
  File "asyncio\windows_events.py", line 446, in select
  File "asyncio\windows_events.py", line 775, in _poll
KeyboardInterrupt

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "asyncio\proactor_events.py", line 688, in close
  File "threading.py", line 1435, in current_thread
SystemError: <built-in function get_ident> returned a result with an exception set
RuntimeError: Result of closing the event loop was 'NULL'.

And I seen the line and it looks that threading.py set's it's get_ident() to _thread.get_ident() and then uses it on the line the traceback mentions. The issue is, it's hard to debug why the _thread.get_ident() function did this.

See also: ZeroIntensity/pyawaitable#36

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions