
    ij                         d Z ddlZddlZddlZddlZ ej
                  dd       d Z ej                   e               ej                           e	d        ej                  d       y)a  Out-of-process payload for the free-threaded switch/critical-section deadlock.

See ``freethread_switch_deadlock.py`` in the repo root for the full write-up.
Before the fix, a greenlet switch swapped C stacks but left any held
``PyCriticalSection`` locks (tracked in ``tstate->critical_section``) locked.
asyncio's ``Task.__step`` holds such a lock on the running task across the step,
so switching into a child greenlet and touching that task from there blocked
forever. A fixed build (and any GIL-enabled build) prints the sentinel; a
regressed free-threaded build deadlocks, and the watchdog turns that hang into a
non-zero exit so the test fails loudly instead of stalling the whole suite.
    N   T)exitc                     K   t        j                         fd} t        j                  |       j                          y w)Nc                  N     j                  d         j                  d        y )Nc                      y N _s    ^/root/.hermes/venv/lib/python3.12/site-packages/greenlet/tests/fail_switch_critical_section.py<lambda>z.main.<locals>.in_child_fiber.<locals>.<lambda>           c                      y r   r	   r
   s    r   r   z.main.<locals>.in_child_fiber.<locals>.<lambda>   r   r   )add_done_callbackremove_done_callback)tasks   r   in_child_fiberzmain.<locals>.in_child_fiber   s!     	~.!!.1r   )asynciocurrent_taskgreenletswitch)r   r   s    @r   mainr      s3     !D2 n%,,.s   >AzSWITCH CS OK)__doc__r   faulthandlersysr   dump_traceback_laterr   runcancel_dump_traceback_laterprintr   r	   r   r   <module>r!      sf   
   
  " ! !"4 0	/ DF  ( ( ( * n  r   