a Z^.c@sgdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z ddl Z ddl mZddl mZejjZddlmZmZmZmZmZGdd d eZeZGd d d eZGd d d eZdS))Queue SimpleQueue JoinableQueueN)EmptyFull) connection)context)debuginfoFinalizeregister_after_fork is_exitingc@seZdZd-ddZddZddZdd Zd.d d Zd/ddZd0ddZ ddZ ddZ ddZ ddZ ddZddZdd Zd!d"Zd#d$Zed%d&Zed'd(Zed)d*Zed+d,ZdS)1rrcCs|dkrddlm}||_tjdd\|_|_||_t |_ t j dkrTd|_n ||_|||_d|_|t j dkrt|tjdS)Nrr) SEM_VALUE_MAXFZduplexwin32)Z synchronizer_maxsizerPipe_reader_writerLock_rlockosZgetpid_opidsysplatform_wlockZBoundedSemaphore_sem _ignore_epipe_resetr r _after_forkselfZmaxsizectxr#./usr/lib64/python3.9/multiprocessing/queues.py__init__%s       zQueue.__init__cCs.t||j|j|j|j|j|j|j|j fSN) rassert_spawningrrrrrrrrr!r#r#r$ __getstate__9s zQueue.__getstate__c Cs0|\|_|_|_|_|_|_|_|_|dSr&) rrrrrrrrrr!Zstater#r#r$ __setstate__>szQueue.__setstate__cCstd|jdddS)NzQueue._after_fork()T) after_fork)r rr(r#r#r$rCszQueue._after_forkFcCsj|r|jntt|_t|_d|_d|_ d|_ d|_ d|_ |j j|_|jj|_|jj|_dSNF) _notemptyZ_at_fork_reinit threading Conditionr collectionsZdeque_buffer_thread _jointhread_joincancelled_closed_closer send_bytes _send_bytesr recv_bytes _recv_bytespoll_poll)r!r,r#r#r$rGs    z Queue._resetTNcCsz|jrtd|d|j||s(t|j8|jdurB||j ||j Wdn1sl0YdSNzQueue z is closed) r6 ValueErrorracquirerr.r3 _start_threadr2appendnotifyr!objblocktimeoutr#r#r$putVs  z Queue.putcCs|jrtd|d|r\|dur\|j|}Wdn1sF0Y|jn||rlt|}|j||s~t zL|r|t}| |st n | st |}|jW|jn |j0t |Sr>) r6r?rr;rreleasetimeZ monotonicr@rr=_ForkingPicklerloads)r!rFrGresZdeadliner#r#r$getbs* &     z Queue.getcCs|j|jjSr&)rr_semlockZ _get_valuer(r#r#r$qsize|sz Queue.qsizecC | Sr&r=r(r#r#r$emptyz Queue.emptycCs |jjSr&)rrO_is_zeror(r#r#r$fullrTz Queue.fullcCs |dSr-)rNr(r#r#r$ get_nowaitrTzQueue.get_nowaitcCs ||dSr-)rHr!rEr#r#r$ put_nowaitrTzQueue.put_nowaitcCsHd|_z$|jW|j}|rDd|_|n|j}|rBd|_|0dS)NT)r6rcloser7)r!rZr#r#r$rZs z Queue.closecCstd|jr|dS)NzQueue.join_thread())r r4r(r#r#r$ join_threadszQueue.join_threadcCs4tdd|_z|jWnty.Yn0dS)NzQueue.cancel_join_thread()T)r r5r4ZcancelZAttributeErrorr(r#r#r$cancel_join_threads  zQueue.cancel_join_threadc Cstd|jtjtj|j|j|j|j |j j |j |j |jfdd|_d|j_td|jtd|jst|jtjt|jgdd|_t|tj|j|jgd d|_dS) NzQueue._start_thread()ZQueueFeederThread)ZtargetZargsZnameTzdoing self._thread.start()z... done self._thread.start()i)Z exitpriorityi )r r2Zclearr/ZThreadr_feedr.r9rrrZr_on_queue_feeder_errorrr3ZdaemonZstartr5r _finalize_joinweakrefZrefr4_finalize_closer7r(r#r#r$rAs2     zQueue._start_threadcCs4td|}|dur(|tdntddS)Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r join)ZtwrZthreadr#r#r$r_s  zQueue._finalize_joincCsBtd|"|t|Wdn1s40YdS)Nztelling queue thread to quit)r rB _sentinelrC)buffernotemptyr#r#r$ras zQueue._finalize_closec Csltd|j}|j} |j} |j} t} tjdkr<|j} |j}nd} z|z|sT| W| n| 0zh| }|| urtd|WWdSt |}| dur||qh| z||W|qh|0qhWnt yYn0Wq@t yd}zf|rt |ddt jkrWYd}~dStr>td|WYd}~dS||||WYd}~q@d}~00q@dS)Nz$starting thread to feed data to piperz%feeder thread got sentinel -- exitingerrnorzerror in queue thread: %s)r r@rIwaitZpopleftrcrrrKdumpsZ IndexErrorZ ExceptionZgetattrrfZEPIPEr r )rdrer8Z writelockrZZ ignore_epipeZonerrorZ queue_semZnacquireZnreleaseZnwaitZbpopleftZsentinelZwacquireZwreleaserEer#r#r$r]sN       z Queue._feedcCsddl}|dS)Nr) tracebackZ print_exc)rirErjr#r#r$r^szQueue._on_queue_feeder_errorr)FTNrl)__name__ __module__ __qualname__r%r)r+rrrHrNrPrSrVrWrYrZr[r\rAZ staticmethodr_rar]r^r#r#r#r$r#s0        =rc@s@eZdZdddZddZddZdd d Zd d ZddZd S)rrcCs*tj|||d|d|_||_dS)N)r"r)rr%Z Semaphore_unfinished_tasksr0_condr r#r#r$r%)s zJoinableQueue.__init__cCst||j|jfSr&)rr)rqrpr(r#r#r$r).rTzJoinableQueue.__getstate__cCs,t||dd|dd\|_|_dS)Ni)rr+rqrpr*r#r#r$r+1zJoinableQueue.__setstate__TNc Cs|jrtd|d|j||s(t|jh|jB|jdurJ||j ||j |j Wdn1s~0YWdn1s0YdSr>)r6r?rr@rr.rqr3rAr2rBrprIrCrDr#r#r$rH5s   zJoinableQueue.putcCsT|j:|jdstd|jjr2|jWdn1sF0YdS)NFz!task_done() called too many times)rqrpr@r?rOrUZ notify_allr(r#r#r$ task_doneBs   zJoinableQueue.task_donecCs@|j&|jjs|jWdn1s20YdSr&)rqrprOrUrgr(r#r#r$rbIs zJoinableQueue.joinrkrl) rmrnror%r)r+rHrsrbr#r#r#r$r's   rc@sNeZdZddZddZddZddZd d Zd d Zd dZ e e j Z dS)rcCsHtjdd\|_|_||_|jj|_tj dkr:d|_ n ||_ dS)NFrr) rrrrrrr<r=rrr)r!r"r#r#r$r%Ts    zSimpleQueue.__init__cCs|j|jdSr&)rrZrr(r#r#r$rZ] zSimpleQueue.closecCrQr&rRr(r#r#r$rSarTzSimpleQueue.emptycCst||j|j|j|jfSr&)rr'rrrrr(r#r#r$r)drtzSimpleQueue.__getstate__cCs"|\|_|_|_|_|jj|_dSr&)rrrrr<r=r*r#r#r$r+hrrzSimpleQueue.__setstate__cCs:|j|j}Wdn1s&0Yt|Sr&)rrr:rKrL)r!rMr#r#r$rNls(zSimpleQueue.getcCsXt|}|jdur"|j|n2|j|j|Wdn1sJ0YdSr&)rKrhrrr8rXr#r#r$rHrs   zSimpleQueue.putN)rmrnror%rZrSr)r+rNrHZ classmethodtypesZ GenericAliasZ__class_getitem__r#r#r#r$rRs  r)Z__all__rrr/r1rJrur`rfZqueuerrZ_multiprocessingZrrZ reductionZForkingPicklerrKZutilr r r r r Zobjectrrcrrr#r#r#r$Z s&  { +