B AFK޽@sdddgZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl Z ddl m Z ddl mZejjZdd lmZmZmZmZmZGd ddeZeZGd ddeZGd ddeZdS) Queue SimpleQueue JoinableQueueN)EmptyFull) connection)context)debuginfoFinalizeregister_after_fork is_exitingc@seZdZd*ddZddZddZdd Zd+d d Zd,ddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zed"d#Zed$d%Zed&d'Zed(d)Zd S)-rrcCs|dkrddlm}||_tjdd\|_|_||_t |_ t j dkrTd|_n ||_|||_d|_|t j dkrt|tjdS)Nrr) SEM_VALUE_MAXF)duplexwin32)Z synchronizer_maxsizerPipe_reader_writerLock_rlockosgetpid_opidsysplatform_wlockZBoundedSemaphore_sem _ignore_epipe _after_forkr r)selfmaxsizectxr$9/opt/alt/python37/lib/python3.7/multiprocessing/queues.py__init__$s       zQueue.__init__cCs.t||j|j|j|j|j|j|j|j fS)N) r assert_spawningrrrrrrrr)r!r$r$r% __getstate__9s zQueue.__getstate__c Cs0|\|_|_|_|_|_|_|_|_|dS)N) rrrrrrrrr )r!stater$r$r% __setstate__>s$zQueue.__setstate__cCsbtdtt|_t|_d|_d|_ d|_ d|_ d|_ |j j|_|jj|_|jj|_dS)NzQueue._after_fork()F)r threading Conditionr _notempty collectionsdeque_buffer_thread _jointhread_joincancelled_closed_closer send_bytes _send_bytesr recv_bytes _recv_bytespoll_poll)r!r$r$r%r Cs   zQueue._after_forkTNc CsP|j||st|j.|jdkr,||j||jWdQRXdS)N) racquirerr-r1 _start_threadr0appendnotify)r!objblocktimeoutr$r$r%putPs  z Queue.putc Cs|r2|dkr2|j|}WdQRX|jnr|rBt|}|j||sTtzB|rv|t}||stn |st|}|jWd|jXt |S)N) rr9rreleasetimeZ monotonicr<rr;_ForkingPicklerloads)r!rArBresZdeadliner$r$r%get[s&      z Queue.getcCs|j|jjS)N)rr_semlock _get_value)r!r$r$r%qsizessz Queue.qsizecCs | S)N)r;)r!r$r$r%emptywsz Queue.emptycCs |jjS)N)rrJ_is_zero)r!r$r$r%fullzsz Queue.fullcCs |dS)NF)rI)r!r$r$r% get_nowait}szQueue.get_nowaitcCs ||dS)NF)rC)r!r@r$r$r% put_nowaitszQueue.put_nowaitcCs2d|_z|jWd|j}|r,d|_|XdS)NT)r4rcloser5)r!rRr$r$r%rRsz Queue.closecCstd|jr|dS)NzQueue.join_thread())r r2)r!r$r$r% join_threadszQueue.join_threadcCs6tdd|_y|jWntk r0YnXdS)NzQueue.cancel_join_thread()T)r r3r2ZcancelAttributeError)r!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 r0clearr+ZThreadr_feedr-r7rrrRr_on_queue_feeder_errorrr1Zdaemonstartr3r _finalize_joinweakrefrefr2_finalize_closer5)r!r$r$r%r=s*        zQueue._start_threadcCs4td|}|dk r(|tdntddS)Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r join)ZtwrZthreadr$r$r%r_s  zQueue._finalize_joinc Cs.td||t|WdQRXdS)Nztelling queue thread to quit)r r> _sentinelr?)buffernotemptyr$r$r%rbs zQueue._finalize_closec CsRtd|j}|j} |j} |j} t} tjdkr<|j} |j}nd} x y|z|sX| Wd| Xybx\| }|| krtd|dSt |}| dkr||qh| z ||Wd|XqhWWnt k rYnXWqDt k rH}zJ|rt |ddt jkrdStr&td|dS||||Wdd}~XYqDXqDWdS)Nz$starting thread to feed data to piperz%feeder thread got sentinel -- exitingerrnorzerror in queue thread: %s)r r<rDwaitpopleftrdrrrFdumps IndexError ExceptiongetattrrgZEPIPErr )rerfr6Z writelockrRZ ignore_epipeonerrorZ queue_semZnacquireZnreleaseZnwaitZbpopleftsentinelZwacquireZwreleaser@er$r$r%r\sR       z Queue._feedcCsddl}|dS)Nr) traceback print_exc)rpr@rqr$r$r%r] szQueue._on_queue_feeder_error)r)TN)TN)__name__ __module__ __qualname__r&r(r*r rCrIrLrMrOrPrQrRrSrUr= staticmethodr_rbr\r]r$r$r$r%r"s&     >c@s@eZdZdddZddZddZdd d Zd d ZddZd S)rrcCs*tj|||d|d|_||_dS)N)r#r)rr&Z Semaphore_unfinished_tasksr,_cond)r!r"r#r$r$r%r& s zJoinableQueue.__init__cCst||j|jfS)N)rr(rxrw)r!r$r$r%r(%szJoinableQueue.__getstate__cCs,t||dd|dd\|_|_dS)N)rr*rxrw)r!r)r$r$r%r*(szJoinableQueue.__setstate__TNc Csl|j||st|jJ|j8|jdkr4||j||j |j WdQRXWdQRXdS)N) rr<rr-rxr1r=r0r>rwrDr?)r!r@rArBr$r$r%rC,s   zJoinableQueue.putc Cs@|j0|jdstd|jjr2|jWdQRXdS)NFz!task_done() called too many times)rxrwr< ValueErrorrJrNZ notify_all)r!r$r$r% task_done8s   zJoinableQueue.task_donec Cs,|j|jjs|jWdQRXdS)N)rxrwrJrNrh)r!r$r$r%rc?s zJoinableQueue.join)r)TN) rsrtrur&r(r*rCr{rcr$r$r$r%rs   c@s<eZdZddZddZddZddZd d Zd d Zd S)rcCsHtjdd\|_|_||_|jj|_tj dkr:d|_ n ||_ dS)NF)rr) rrrrrrr:r;rrr)r!r#r$r$r%r&Js    zSimpleQueue.__init__cCs | S)N)r;)r!r$r$r%rMSszSimpleQueue.emptycCst||j|j|j|jfS)N)r r'rrrr)r!r$r$r%r(Vs zSimpleQueue.__getstate__cCs"|\|_|_|_|_|jj|_dS)N)rrrrr:r;)r!r)r$r$r%r*ZszSimpleQueue.__setstate__c Cs&|j|j}WdQRXt|S)N)rrr8rFrG)r!rHr$r$r%rI^szSimpleQueue.getc CsDt|}|jdkr"|j|n|j|j|WdQRXdS)N)rFrjrrr6)r!r@r$r$r%rCds   zSimpleQueue.putN) rsrtrur&rMr(r*rIrCr$r$r$r%rHs  )__all__rrr+r.rEr`rgZqueuerrZ_multiprocessingrr Z reductionZForkingPicklerrFutilr r r r robjectrrdrrr$r$r$r% s$   s *