Skip to content

Enhance critical section held assertions for objects in free-threading #135380

Open
@kumaraditya303

Description

@kumaraditya303

Currently the critical section held assertions on objects are not helpful as it doesn't prints the object of which the critical section should be held, it is helpful for debugging to print the object along with a message that critical section of object is not held.

Before:

./python -m test test_asyncio
Using random seed: 3111514708
0:00:00 load avg: 21.32 Run 34 tests sequentially in a single process
0:00:00 load avg: 21.32 [ 1/34] test_asyncio.test_base_events
python: ./Include/internal/pycore_critical_section.h:236: void _PyCriticalSection_AssertHeld(PyMutex *): Assertion `cs != NULL && cs->_cs_mutex == mutex' failed.
Fatal Python error: Aborted

After:

 ./python -m test test_asyncio
Using random seed: 3608858608
0:00:00 load avg: 0.25 Run 34 tests sequentially in a single process
0:00:00 load avg: 0.25 [ 1/34] test_asyncio.test_base_events
./Include/internal/pycore_critical_section.h:259: _PyCriticalSection_AssertHeldObj: Assertion "(cs != ((void*)0) && cs->_cs_mutex == mutex)" failed: Critical section of object is not held
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x20000566ce0
object refcount : 3
object type     : 0x20000f74610
object type name: _asyncio.Task
object repr     : <Task pending name='Task-118' coro=<BaseEventLoop._create_server_getaddrinfo() running at /home/realkumaraditya/cpython/Lib/asyncio/base_events.py:1500>>

Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: initialized

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions