
    sh                         S SK r S SKrS SKrS SKJr  S SKJrJr  S SK	r	 " S S\	R                  5      r " S S\	R                  5      r\S:X  a  \	R                  " 5         gg)	    N)captured_stdout)	vectorizeguvectorizec                   $    \ rS rSrSrS rS rSrg)TestParUfuncIssues   Fc                     [        SSS9S 5       nSnUS:  ac  [        R                  " U5        [        R                  " S5      =p4[        R
                  R                  X4-   U" X45      5        US-  nUS:  a  Mb  g	g	)
z
Related to #89.
This does not test #89 but tests the fix for it.
We want to make sure the worker threads can be used multiple times
and with different time gap between each execution.
zfloat64(float64, float64)parallel)targetc                 
    X-   $ N )abs     ڃ/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/tests/npyufunc/test_parallel_ufunc_issues.pyfnv4TestParUfuncIssues.test_thread_response.<locals>.fnv   s	    5L       gh㈵>i    N)r   timesleepnparangetestingassert_equal)selfr   
sleep_timer   r   s        r   test_thread_response'TestParUfuncIssues.test_thread_response   sx     
.z	B	 
C	 
7"JJz"IIe$$AJJ##AE3q95!OJ 7"r   c                 "  ^^ [         R                  " S[         R                  5      nSmU4S jnU" U5      m[        S/SSS9U4S j5       nS	 GH!  n[        R
                  " U[        R                  S
9nUR                  5       n[        5        nU" U5      nSSS5        WR                  5       n	UR                  5         [        [        S U	R                  5       5      5      n
[        U5       Vs/ s H  n[        US-  5      PM     nnU[        U5       Vs/ s H  nTUS-     PM     sn-  n[        U5      nU R!                  X5        [        R"                  R%                  WSU-  5        GM$     g! , (       d  f       N= fs  snf s  snf )z,
Testing issue #1998 due to GIL reacquiring
N
abcdefghijc                 "   > [        TU    5        g r   printx
characterss    r   bar;TestParUfuncIssues.test_gil_reacquire_deadlock.<locals>.bar+       *Q- r   zint32(int32)r
   Tr   nopythonc                 @   > [        U S-  5        T" U S-  5        U S-  $ )N
   r   r$   )r'   cbars    r   foo;TestParUfuncIssues.test_gil_reacquire_deadlock.<locals>.foo1   s"    !b&MRLq5Lr   r   r/   d   i  dtypec                 "    U R                  5       $ r   stripr'   s    r   <lambda>@TestParUfuncIssues.test_gil_reacquire_deadlock.<locals>.<lambda>D   
    aggir   r/   r   )ctypes	CFUNCTYPEc_int32r   r   r   int32copyr   getvalueclosesortedmap
splitlinesrangestrassertEqualr   r   r   protor)   r1   nelemr   acopybufgotstdout
got_outputr'   expected_outputr0   r(   s                @@r   test_gil_reacquire_deadlock.TestParUfuncIssues.test_gil_reacquire_deadlock#   sH   
   v~~6!
	! Sz 
N#J	F	 
G	 (E		%rxx0AFFHE "c!f #\\^FIIK$79J9J9L MNJ49%LALqs1r6{LOAE%LILq
1r6 2LIIO$_5OZ9JJ##CU3# (
 #" BIs   	E62FF6
F	r   N)__name__
__module____qualname____firstlineno___numba_parallel_test_r   rT   __static_attributes__r   r   r   r   r      s    !((4r   r   c                       \ rS rSrSrS rSrg)TestParGUfuncIssuesO   Fc                 $  ^^ [         R                  " S[         R                  5      nSmU4S jnU" U5      m[        S/SSSS9U4S	 j5       nS
 GH!  n[        R
                  " U[        R                  S9nUR                  5       n[        5        nU" U5      nSSS5        WR                  5       n	UR                  5         [        [        S U	R                  5       5      5      n
[        U5       Vs/ s H  n[        US-  5      PM     nnU[        U5       Vs/ s H  nTUS-     PM     sn-  n[        U5      nU R!                  X5        [        R"                  R%                  WSU-  5        GM$     g! , (       d  f       N= fs  snf s  snf )zB
Testing similar issue to #1998 due to GIL reacquiring for Gufunc
Nr"   c                 "   > [        TU    5        g r   r$   r&   s    r   r)   <TestParGUfuncIssues.test_gil_reacquire_deadlock.<locals>.bar[   r+   r   z(int32, int32[:])z()->()r
   Tr,   c                 H   > [        U S-  5        T" U S-  5        U S-  US'   g )Nr/   r   r   r$   )r'   outr0   s     r   r1   <TestParGUfuncIssues.test_gil_reacquire_deadlock.<locals>.fooa   s(     !b&MRLUCFr   r3   r5   c                 "    U R                  5       $ r   r8   r:   s    r   r;   ATestParGUfuncIssues.test_gil_reacquire_deadlock.<locals>.<lambda>u   r=   r   r/   r   )r>   r?   r@   r   r   r   rA   rB   r   rC   rD   rE   rF   rG   rH   rI   rJ   r   r   rK   s                @@r   rT   /TestParGUfuncIssues.test_gil_reacquire_deadlockS   sM   
   v~~6!
	! Sz 
)*H&
7	
7	 (E		%rxx0AFFHE "c!f #\\^FIIK$79J9J9L MNJ49%LALqs1r6{LOAE%LILq
1r6 2LIIO$_5OZ9JJ##CU3# (
 #" BIs   	E73FF7
F	r   N)rV   rW   rX   rY   rZ   rT   r[   r   r   r   r]   r]   O   s    !)4r   r]   __main__)r   r>   numpyr   numba.tests.supportr   numbar   r   unittestTestCaser   r]   rV   mainr   r   r   <module>ro      sW       / ( @4** @4H-4(++ -4` zMMO r   