
    ⾙h1                     
   d dl Z d dlZd dlZd dlZd dlZd dlZddlmZ ddlmZ ddl	m
Z
 d dlmZ d dlmZmZ ddlmZmZmZmZmZmZ dd	lmZ g d
Z G d d      Z e       Z G d de      Z G d d      Z G d de      Zy)    N   )
connection)context)	get_errno)	monotonic)EmptyFull)debugerrorinfoFinalizeregister_after_fork
is_exiting)ForkingPickler)QueueSimpleQueueJoinableQueuec                       e Zd ZdZddZd Zd Zd ZddZddZ	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zed        Zed        Zed        Zy)r   z4
    Queue type using a pipe, buffer and thread
    c                    	 |d   }|dk  rddlm} || _        t        j                  d      \  | _        | _        |j                         | _
        t        j                         | _        t        j                  dk(  rd | _        n|j                         | _        |j#                  |      | _        d| _        | j)                          t        j                  dk7  rt+        | t,        j(                         y y # t         $ r t        d      w xY w)	Nctxz-missing 1 required keyword-only argument: ctxr   r   )SEM_VALUE_MAXFduplexwin32)KeyError	TypeErrorsynchronizer   _maxsizer   Pipe_reader_writerLock_rlockosgetpid_opidsysplatform_wlockBoundedSemaphore_sem_ignore_epipe_after_forkr   r   selfmaxsizeargskwargsr   s        K/var/www/Befach/backend/env/lib/python3.12/site-packages/billiard/queues.py__init__zQueue.__init__#   s    	M-C a<=%/__E%B"dlhhjYY[
<<7"DK((*DK((1	"<<7"e&7&78 #'  	MKLL	Ms   C6 6Dc                     t        j                  |        | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  fS N)
r   assert_spawningr,   r   r    r!   r#   r)   r+   r&   r/   s    r3   __getstate__zQueue.__getstate__<   sP    %""DMM4<<T[[$))TZZA 	A    c           	          |\  | _         | _        | _        | _        | _        | _        | _        | _        | j                          y r6   )	r,   r   r    r!   r#   r)   r+   r&   r-   r/   states     r3   __setstate__zQueue.__setstate__A   s8    <A	:	T]DL$,	dk49djr:   c                    t        d       t        j                  t        j                               | _        t        j                         | _        d | _        d | _	        d| _
        d| _        d | _        | j                  j                  | _        | j                   j"                  | _        | j                  j&                  | _        | j                   j(                  | _        | j                   j,                  | _        y )NzQueue._after_fork()F)r
   	threading	Conditionr"   	_notemptycollectionsdeque_buffer_thread_jointhread_joincancelled_closed_closer!   send_send_bytesr    recv_recv
send_bytes
recv_bytes_recv_bytespoll_pollr8   s    r3   r-   zQueue._after_forkF   s    #$",,Y^^-=>"((*#<<,,\\&&
<<22<<22\\&&
r:   Nc                 H   | j                   rJ | j                  j                  ||      st        | j                  5  | j
                  | j                          | j                  j                  |       | j                  j                          d d d        y # 1 sw Y   y xY wr6   )
rI   r+   acquirer	   rB   rF   _start_threadrE   appendnotifyr/   objblocktimeouts       r3   putz	Queue.putU   s|    <<yy  0J^^ 	$||#""$LL$NN!!#		$ 	$ 	$s   ABB!c                 x   |rB|@| j                   5  | j                         }d d d        | j                  j                          n|rt	               |z   }| j                   j                  ||      st        	 |r)t	               z
  }|dk  s| j                  |      st        | j                         st        | j                         }| j                  j                          | j                   j                          t        j                        S # 1 sw Y   xY w# | j                   j                          w xY w)Nr   )
r#   rQ   r+   releaser   rU   r   rS   r   loads)r/   r[   r\   resdeadlines        r3   getz	Queue.get`   s    W_ )&&()II $;0;;&&ug6
&&4G{$**W*=#K&&(		!!###%##C((+) )& ##%s   D7A+D DD9c                 d    | j                   | j                  j                  j                         z
  S r6   )r   r+   _semlock
_get_valuer8   s    r3   qsizezQueue.qsizey   s&     }}tyy11<<>>>r:   c                 $    | j                          S r6   rS   r8   s    r3   emptyzQueue.empty~       ::<r:   c                 J    | j                   j                  j                         S r6   )r+   re   _is_zeror8   s    r3   fullz
Queue.full   s    yy!!**,,r:   c                 $    | j                  d      S NF)rc   r8   s    r3   
get_nowaitzQueue.get_nowait   s    xxr:   c                 &    | j                  |d      S rp   )r]   r/   rZ   s     r3   
put_nowaitzQueue.put_nowait   s    xxU##r:   c                     d| _         	 | j                  j                          | j                  }|rd | _         |        y y # | j                  }|rd | _         |        w w xY w)NT)rI   r    closerJ   )r/   rv   s     r3   rv   zQueue.close   s\    	LL KKE"  KKE" s   A A c                 p    t        d       | j                  sJ | j                  r| j                          y y )NzQueue.join_thread())r
   rI   rG   r8   s    r3   join_threadzQueue.join_thread   s1    #$||| r:   c                 |    t        d       d| _        	 | j                  j                          y # t        $ r Y y w xY w)NzQueue.cancel_join_thread()T)r
   rH   rG   cancelAttributeErrorr8   s    r3   cancel_join_threadzQueue.cancel_join_thread   s<    *+"	##% 		s   / 	;;c           	          t        d       | j                  j                          t        j                  t
        j                  | j                  | j                  | j                  | j                  | j                  j                  | j                  fd      | _        d| j                  _        t        d       | j                  j                          t        d       | j                   t#        j$                         k(  }| j&                  sL|sJt)        | j                  t
        j*                  t-        j.                  | j                        gd      | _        t)        | t
        j2                  | j                  | j                  gd	      | _        y )
NzQueue._start_thread()QueueFeederThread)targetr1   nameTzdoing self._thread.start()z... done self._thread.start())exitpriority
   )r
   rE   clearr@   Threadr   _feedrB   rL   r)   r!   rv   r,   rF   daemonstartr&   r$   r%   rH   r   _finalize_joinweakrefrefrG   _finalize_closerJ   )r/   created_by_this_processs     r3   rV   zQueue._start_thread   s    %& 	 '';;,,0@0@++t||1143E3EG$	
 #*+-. $(::#<""+B'e22T\\*+ D %''\\4>>*
r:   c                 z    t        d        |        }||j                          t        d       y t        d       y )Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r
   join)twrthreads     r3   r   zQueue._finalize_join   s3    $%KKM+,12r:   c                     t        d       |5  | j                  t               |j                          d d d        y # 1 sw Y   y xY w)Nztelling queue thread to quit)r
   rW   	_sentinelrX   )buffernotemptys     r3   r   zQueue._finalize_close   s9    ,- 	MM)$OO	 	 	s	   &=Ac                 (   t        d       |j                  }|j                  }|j                  }| j                  }	t
        }
t        j                  dk7  r|j                  }|j                  }nd }	 	  |        	 | s |         |        	 	  |	       }||
u rt        d        |        y t        j                  |      }|	 ||       n |        	  ||                V#  |        w xY w#          w xY w# t        $ r Y nw xY w# t        $ r~}|r!t        |      t        j                  k(  rY d }~y 	 t               rt!        d|d       n"t#        d|d      sdd l}|j'                          n# t        $ r Y nw xY wY d }~y Y d }~y d }~ww xY w)Nz$starting thread to feed data to piper   z%feeder thread got sentinel -- exitingzerror in queue thread: %rT)exc_infor   )r
   rU   r_   waitpopleftr   r'   r(   r   dumps
IndexError	Exceptionr   errnoEPIPEr   r   r   	traceback	print_exc)r   r   rO   	writelockrv   ignore_epipenacquirenreleasenwaitbpopleftsentinelwacquirewreleaserZ   excr   s                   r3   r   zQueue._feed   sy   45####>><<7" ((H ((HH,	
!J&j(?!"IJ!G" -2237#+&sO$J+ *3 (
!  J$ !)
! 3 6  		#%++ =
	<4cDI !<c*.0(!++- !	s   1D
 :	C" D
 C: *'C: C. C: "	C++D
 .	C77C: :	DD
 DD
 
	FF7;E32F3	E?<F>E??FFr   TN)__name__
__module____qualname____doc__r4   r9   r>   r-   r]   rc   rg   rj   rn   rq   rt   rv   rx   r|   rV   staticmethodr   r   r    r:   r3   r   r      s    92A

'	$)2?
 -$$
L 3 3   : :r:   r   c                   8    e Zd ZdZd	dZd Zd Zd
dZd Zd Z	y)r   z
    A queue type which also supports join() and task_done() methods

    Note that if you do not call task_done() for each finished task then
    eventually the counter's semaphore may overflow causing Bad Things
    to happen.
    c                     	 |d   }t        j                  | ||       |j	                  d      | _        |j                         | _        y # t         $ r t        d      w xY w)Nr   z(missing 1 required keyword argument: ctx)r   r   )r   r   r   r4   	Semaphore_unfinished_tasksrA   _condr.   s        r3   r4   zJoinableQueue.__init__"  sb    	H-C 	tW#.!$q!1]]_
	  	HFGG	Hs   A A c                 ^    t         j                  |       | j                  | j                  fz   S r6   )r   r9   r   r   r8   s    r3   r9   zJoinableQueue.__getstate__+  s'    !!$'4::t7M7M*NNNr:   c                 Z    t         j                  | |d d        |dd  \  | _        | _        y )N)r   r>   r   r   r<   s     r3   r>   zJoinableQueue.__setstate__.  s-    4s,-223Z*
D*r:   Nc                    | j                   rJ | j                  j                  ||      st        | j                  5  | j
                  5  | j                  | j                          | j                  j                  |       | j                  j                          | j                  j                          d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr6   )rI   r+   rU   r	   rB   r   rF   rV   rE   rW   r   r_   rX   rY   s       r3   r]   zJoinableQueue.put2  s    <<yy  0J^^ 	( (<<'&&(##C(&&..0%%'(	( 	(( (	( 	(s$   C
A,C6CC	CCc                    | j                   5  | j                  j                  d      st        d      | j                  j                  j                         r| j                   j                          d d d        y # 1 sw Y   y xY w)NFz!task_done() called too many times)r   r   rU   
ValueErrorre   rm   
notify_allr8   s    r3   	task_donezJoinableQueue.task_done?  sf    ZZ 	())11%8 !DEE%%..779

%%'		( 	( 	(s   A%A;;Bc                     | j                   5  | j                  j                  j                         s| j                   j	                          d d d        y # 1 sw Y   y xY wr6   )r   r   re   rm   r   r8   s    r3   r   zJoinableQueue.joinF  sD    ZZ 	"))22;;=

!	" 	" 	"s   ?AAr   r   )
r   r   r   r   r4   r9   r>   r]   r   r   r   r:   r3   r   r     s&    %O8(("r:   r   c                   H    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zy)_SimpleQueuez<
    Simplified Queue type -- really just a locked pipe
    Nc                     t        j                  d||      \  | _        | _        | j                  j                  | _        d x| _        | _        y )NF)r   	rnonblock	wnonblock)r   r   r    r!   rR   rS   r#   r)   )r/   r   r   r   s       r3   r4   z_SimpleQueue.__init__Q  sA    %/__I&
"dl \\&&
$((dkr:   c                 $    | j                          S r6   ri   r8   s    r3   rj   z_SimpleQueue.emptyX  rk   r:   c                     t        j                  |        | j                  | j                  | j                  | j
                  fS r6   )r   r7   r    r!   r#   r)   r8   s    r3   r9   z_SimpleQueue.__getstate__[  s/    %dllDKKEEr:   c                 :    |\  | _         | _        | _        | _        y r6   )r    r!   r#   r)   r<   s     r3   r>   z_SimpleQueue.__setstate___  s    AF>t|T[$+r:   c                 6    | j                   j                         S r6   )r    rP   r8   s    r3   get_payloadz_SimpleQueue.get_payloadb  s    ||&&((r:   c                 :    | j                   j                  |       y r6   )r!   rO   r/   values     r3   send_payloadz_SimpleQueue.send_payloade  s    &r:   c                 H    t        j                  | j                               S r6   )r   r`   r   r8   s    r3   rc   z_SimpleQueue.geth  s    ##D$4$4$677r:   c                 L    | j                  t        j                  |             y r6   )r   r   r   rs   s     r3   r]   z_SimpleQueue.putl  s    ...s34r:   c                     | j                   "	 | j                   j                          d | _         | j                  #	 | j                  j                          d | _        y y # d | _         w xY w# d | _        w xY wr6   )r    rv   r!   r8   s    r3   rv   z_SimpleQueue.closep  sh    <<#$""$#<<#$""$#	 $  $  $s   A A+ 	A(+	A4)FFN)r   r   r   r   r4   rj   r9   r>   r   r   rc   r]   rv   r   r:   r3   r   r   L  s6    ) FG)'85$r:   r   c                       e Zd Zd Zd Zd Zy)r   c                    	 |d   }t        j                  d      \  | _        | _        |j                         | _        t        j                  dk7  r|j                         | _
        y d | _
        y # t         $ r t        d      w xY w)Nr   z&missing required keyword argument: ctxFr   r   )r   r   r   r   r    r!   r"   r#   r'   r(   r)   )r/   r1   r2   r   s       r3   r4   zSimpleQueue.__init__  st    	F-C &0__E%B"dlhhj$'LLG$;chhj	  	FDEE	Fs   A0 0Bc                 z    | j                   5  | j                  j                         cd d d        S # 1 sw Y   y xY wr6   )r#   r    rP   r8   s    r3   r   zSimpleQueue.get_payload  s.    [[ 	-<<**,	- 	- 	-s   1:c                     | j                   | j                  j                  |       y | j                   5  | j                  j                  |       d d d        y # 1 sw Y   y xY wr6   )r)   r!   rO   r   s     r3   r   zSimpleQueue.send_payload  sL    ;;LL##E* /''./ / /s   AA#N)r   r   r   r4   r   r   r   r:   r3   r   r   ~  s    F-/r:   r   ) r'   r$   r@   rC   r   r    r   r   compatr   timer   queuer   r	   utilr
   r   r   r   r   r   	reductionr   __all__r   objectr   r   r   r   r   r:   r3   <module>r      sv     	           &
3u un H	0"E 0"f/$ /$d/, /r:   