a xa.@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_rlockosgetpid_opidsysplatform_wlockZBoundedSemaphore_sem _ignore_epipe_resetr r _after_forkselfmaxsizectxr&,/usr/lib/python3.9/multiprocessing/queues.py__init__%s       zQueue.__init__cCs.t||j|j|j|j|j|j|j|j fSN) r assert_spawningrrrrrrrrr#r&r&r' __getstate__9s zQueue.__getstate__c Cs0|\|_|_|_|_|_|_|_|_|dSr)) rrrrrrrrr r#stater&r&r' __setstate__>szQueue.__setstate__cCstd|jdddS)NzQueue._after_fork()T) after_fork)r r r+r&r&r'r!CszQueue._after_forkFcCsj|r|jntt|_t|_d|_d|_ d|_ d|_ d|_ |j j|_|jj|_|jj|_dSNF) _notempty_at_fork_reinit threading Conditionr collectionsdeque_buffer_thread _jointhread_joincancelled_closed_closer send_bytes _send_bytesr recv_bytes _recv_bytespoll_poll)r#r0r&r&r'r Gs    z Queue._resetTNcCsz|jrtd|d|j||s(t|j8|jdurB||j ||j Wdn1sl0YdSNzQueue z is closed) r< ValueErrorracquirerr2r9 _start_threadr8appendnotifyr#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 |SrD) r<rErrArreleasetime monotonicrFrrC_ForkingPicklerloads)r#rLrMresZdeadliner&r&r'getbs* &     z Queue.getcCs|j|jjSr))rr_semlockZ _get_valuer+r&r&r'qsize|sz Queue.qsizecCs | Sr)rCr+r&r&r'emptysz Queue.emptycCs |jjSr))rrV_is_zeror+r&r&r'fullsz Queue.fullcCs |dSr1)rUr+r&r&r' get_nowaitszQueue.get_nowaitcCs ||dSr1)rNr#rKr&r&r' put_nowaitszQueue.put_nowaitcCsHd|_z$|jW|j}|rDd|_|n|j}|rBd|_|0dS)NT)r<rcloser=)r#r_r&r&r'r_s z Queue.closecCs.td|jsJd||jr*|dS)NzQueue.join_thread()zQueue {0!r} not closed)r r<formatr:r+r&r&r' join_threadszQueue.join_threadcCs4tdd|_z|jWnty.Yn0dS)NzQueue.cancel_join_thread()T)r r;r:ZcancelAttributeErrorr+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)targetargsnameTzdoing self._thread.start()z... done self._thread.start())Z exitpriority )r r8clearr4ZThreadr_feedr2r?rrr_r_on_queue_feeder_errorrr9Zdaemonstartr;r _finalize_joinweakrefrefr:_finalize_closer=r+r&r&r'rGs2     zQueue._start_threadcCs4td|}|dur(|tdntddS)Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r join)Ztwrthreadr&r&r'rms  zQueue._finalize_joincCsBtd|"|t|Wdn1s40YdS)Nztelling queue thread to quit)r rH _sentinelrI)buffernotemptyr&r&r'rps 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 rFrOwaitpopleftrsrrrRdumps IndexError ExceptiongetattrrvZEPIPErr )rtrur>Z writelockr_Z ignore_epipeonerrorZ queue_semZnacquireZnreleaseZnwaitZbpopleftsentinelZwacquireZwreleaserKer&r&r'rjsN       z Queue._feedcCsddl}|dS)z Private API hook called when feeding data in the background thread raises an exception. For overriding by concurrent.futures. rN) traceback print_exc)rrKrr&r&r'rkszQueue._on_queue_feeder_error)r)F)TN)TN)__name__ __module__ __qualname__r(r,r/r!r rNrUrWrYr[r\r^r_rarcrG staticmethodrmrprjrkr&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_tasksr5_condr"r&r&r'r()s zJoinableQueue.__init__cCst||j|jfSr))rr,rrr+r&r&r'r,.szJoinableQueue.__getstate__cCs,t||dd|dd\|_|_dS)N)rr/rrr-r&r&r'r/1szJoinableQueue.__setstate__TNc Cs|jrtd|d|j||s(t|jh|jB|jdurJ||j ||j |j Wdn1s~0YWdn1s0YdSrD)r<rErrFrr2rr9rGr8rHrrOrIrJr&r&r'rN5s   zJoinableQueue.putcCsT|j:|jdstd|jjr2|jWdn1sF0YdS)NFz!task_done() called too many times)rrrFrErVrZZ notify_allr+r&r&r' task_doneBs   zJoinableQueue.task_donecCs@|j&|jjs|jWdn1s20YdSr))rrrVrZrwr+r&r&r'rqIs zJoinableQueue.join)r)TN) rrrr(r,r/rNrrqr&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) rrrrrrrBrCrrr)r#r%r&r&r'r(Ts    zSimpleQueue.__init__cCs|j|jdSr))rr_rr+r&r&r'r_]s zSimpleQueue.closecCs | Sr)rXr+r&r&r'rYaszSimpleQueue.emptycCst||j|j|j|jfSr))r r*rrrrr+r&r&r'r,ds zSimpleQueue.__getstate__cCs"|\|_|_|_|_|jj|_dSr))rrrrrBrCr-r&r&r'r/hszSimpleQueue.__setstate__cCs:|j|j}Wdn1s&0Yt|Sr))rrr@rRrS)r#rTr&r&r'rUls(zSimpleQueue.getcCsXt|}|jdur"|j|n2|j|j|Wdn1sJ0YdSr))rRryrrr>r]r&r&r'rNrs   zSimpleQueue.putN)rrrr(r_rYr,r/rUrN classmethodtypes GenericAlias__class_getitem__r&r&r&r'rRs  r)__all__rrr4r6rPrrnrvZqueuerrZ_multiprocessingrr Z reductionZForkingPicklerrRutilr r r r robjectrrsrrr&r&r&r' s&  { +