
    Yj                         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           dS )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        |                                            d S )Nc                  `                          d                                 d            d S )Nc                     d S N _s    o/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/greenlet/tests/fail_switch_critical_section.py<lambda>z.main.<locals>.in_child_fiber.<locals>.<lambda>   s         c                     d S r   r	   r
   s    r   r   z.main.<locals>.in_child_fiber.<locals>.<lambda>   s    D r   )add_done_callbackremove_done_callback)tasks   r   in_child_fiberzmain.<locals>.in_child_fiber   s7     	~~...!!..11111r   )asynciocurrent_taskgreenletswitch)r   r   s    @r   mainr      sS      !!D2 2 2 2 2 n%%,,.....r   zSWITCH CS OK)__doc__r   faulthandlersysr   dump_traceback_laterr   runcancel_dump_traceback_laterprintr   r	   r   r   <module>r       s   
 
      



  " !"4 0 0 0 0	/ 	/ 	/ DDFF    ( ( * * * n    r   