3 \ *ã@sÐdddgZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl Z ddl m Z ddl mZejjZdd lmZmZmZmZmZGd d„deƒZeƒZGd d„deƒZGd d„deƒZdS) ÚQueueÚ SimpleQueueÚ JoinableQueueéN)ÚEmptyÚFullé)Ú connection)Úcontext)ÚdebugÚinfoÚFinalizeÚregister_after_forkÚ is_exitingc@s®eZdZd(dd„Zdd„Zdd„Zdd „Zd)d d „Zd*dd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zd d!„Zed"d#„ƒZed$d%„ƒZed&d'„ƒZd S)+rrcCs’|dkrddlm}||_tjdd�\|_|_|jƒ|_t j ƒ|_ t j dkrTd|_n |jƒ|_|j|ƒ|_d|_|jƒt j dkrŽt|tjƒdS)Nrr)Ú SEM_VALUE_MAXF)ÚduplexÚwin32)Z synchronizerÚ_maxsizerÚPipeÚ_readerÚ_writerÚLockÚ_rlockÚosÚgetpidÚ_opidÚsysÚplatformÚ_wlockZBoundedSemaphoreÚ_semÚ _ignore_epipeÚ _after_forkr r)ÚselfÚmaxsizeÚctx©r$ú./usr/lib64/python3.6/multiprocessing/queues.pyÚ__init__$s       zQueue.__init__cCs.tj|ƒ|j|j|j|j|j|j|j|j fS)N) r Úassert_spawningrrrrrrrr)r!r$r$r%Ú __getstate__9s zQueue.__getstate__c Cs0|\|_|_|_|_|_|_|_|_|jƒdS)N) rrrrrrrrr )r!Ústater$r$r%Ú __setstate__>s$zQueue.__setstate__cCsbtdƒtjtjƒƒ|_tjƒ|_d|_d|_ d|_ d|_ d|_ |j j|_|jj|_|jj|_dS)NzQueue._after_fork()F)r Ú threadingÚ ConditionrÚ _notemptyÚ collectionsÚdequeÚ_bufferÚ_threadÚ _jointhreadÚ_joincancelledÚ_closedÚ_closerÚ send_bytesÚ _send_bytesrÚ recv_bytesÚ _recv_bytesÚpollÚ_poll)r!r$r$r%r Cs   zQueue._after_forkTNc CsP|jj||ƒst‚|j�.|jdkr,|jƒ|jj|ƒ|jjƒWdQRXdS)N) rÚacquirerr-r1Ú _start_threadr0ÚappendÚnotify)r!ÚobjÚblockÚtimeoutr$r$r%ÚputPs  z Queue.putc Cs®|r2|dkr2|j�|jƒ}WdQRX|jjƒnr|rBtjƒ|}|jj||ƒsTt‚zB|rv|tjƒ}|j|ƒs‚t‚n |jƒs‚t‚|jƒ}|jjƒWd|jjƒXt j |ƒS)N) rr9rÚreleaseÚtimeZ monotonicr<rr;Ú_ForkingPicklerÚloads)r!rArBÚresZdeadliner$r$r%Úget[s&      z Queue.getcCs|j|jjjƒS)N)rrÚ_semlockZ _get_value)r!r$r$r%Úqsizessz Queue.qsizecCs |jƒ S)N)r;)r!r$r$r%Úemptywsz Queue.emptycCs |jjjƒS)N)rrJÚ_is_zero)r!r$r$r%Úfullzsz Queue.fullcCs |jdƒS)NF)rI)r!r$r$r%Ú get_nowait}szQueue.get_nowaitcCs |j|dƒS)NF)rC)r!r@r$r$r%Ú put_nowait€szQueue.put_nowaitc Cs2d|_z|jjƒWd|j}|r,d|_|ƒXdS)NT)r4rÚcloser5)r!rQr$r$r%rQƒsz Queue.closecCstdƒ|jr|jƒdS)NzQueue.join_thread())r r2)r!r$r$r%Ú join_thread�szQueue.join_threadc Cs6tdƒd|_y|jjƒWntk r0YnXdS)NzQueue.cancel_join_thread()T)r r3r2ZcancelÚAttributeError)r!r$r$r%Úcancel_join_thread“s zQueue.cancel_join_threadcCs¨tdƒ|jjƒtjtj|j|j|j|j |j j |j fdd�|_ d|j _tdƒ|j jƒtdƒ|jsˆt|j tjtj|j ƒgd d�|_t|tj|j|jgd d�|_dS) NzQueue._start_thread()ZQueueFeederThread)ÚtargetÚargsÚnameTzdoing self._thread.start()z... done self._thread.start()é)Z exitpriorityé éûÿÿÿ)r r0Úclearr+ZThreadrÚ_feedr-r7rrrQrr1ZdaemonÚstartr3r Ú_finalize_joinÚweakrefÚrefr2Ú_finalize_closer5)r!r$r$r%r=›s(       zQueue._start_threadcCs4tdƒ|ƒ}|dk r(|jƒtdƒntdƒdS)Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r Újoin)ZtwrZthreadr$r$r%r^ºs  zQueue._finalize_joinc Cs.tdƒ|�|jtƒ|jƒWdQRXdS)Nztelling queue thread to quit)r r>Ú _sentinelr?)ÚbufferÚnotemptyr$r$r%raÄs zQueue._finalize_closecCsPtdƒ|j}|j}|j}|j} t} tjdkr<|j} |j} nd} �xyš|ƒz|sX|ƒWd|ƒXybx\| ƒ} | | krˆtdƒ|ƒdStj | ƒ} | dkr¤|| ƒqh| ƒz || ƒWd| ƒXqhWWnt k rÚYnXWqDt k �rF}zJ|�rt |ddƒt jk�rdStƒ�r&td|ƒdSddl}|jƒWYdd}~XqDXqDWdS)Nz$starting thread to feed data to piperz%feeder thread got sentinel -- exitingÚerrnorzerror in queue thread: %s)r r<rDÚwaitÚpopleftrcrrrFÚdumpsÚ IndexErrorÚ ExceptionÚgetattrrfZEPIPErr Ú tracebackÚ print_exc)rdrer6Z writelockrQZ ignore_epipeZnacquireZnreleaseZnwaitZbpopleftÚsentinelZwacquireZwreleaser@Úermr$r$r%r\ËsR       z Queue._feed)r)TN)TN)Ú__name__Ú __module__Ú __qualname__r&r(r*r rCrIrKrLrNrOrPrQrRrTr=Ú staticmethodr^rar\r$r$r$r%r"s$    c@s@eZdZddd„Zdd„Zdd„Zdd d „Zd d „Zdd„Zd S)rrcCs*tj|||d�|jdƒ|_|jƒ|_dS)N)r#r)rr&Z SemaphoreÚ_unfinished_tasksr,Ú_cond)r!r"r#r$r$r%r&s zJoinableQueue.__init__cCstj|ƒ|j|jfS)N)rr(rvru)r!r$r$r%r(szJoinableQueue.__getstate__cCs,tj||dd…ƒ|dd…\|_|_dS)Nééþÿÿÿrx)rr*rvru)r!r)r$r$r%r*szJoinableQueue.__setstate__TNcCsl|jj||ƒst‚|j�J|j�8|jdkr4|jƒ|jj|ƒ|j j ƒ|jj ƒWdQRXWdQRXdS)N) rr<rr-rvr1r=r0r>rurDr?)r!r@rArBr$r$r%rCs   zJoinableQueue.putc Cs@|j�0|jjdƒstdƒ‚|jjjƒr2|jjƒWdQRXdS)NFz!task_done() called too many times)rvrur<Ú ValueErrorrJrMZ notify_all)r!r$r$r%Ú task_done's   zJoinableQueue.task_donec Cs,|j�|jjjƒs|jjƒWdQRXdS)N)rvrurJrMrg)r!r$r$r%rb.s zJoinableQueue.join)r)TN) rqrrrsr&r(r*rCrzrbr$r$r$r%r s   c@s<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)rcCsHtjdd�\|_|_|jƒ|_|jj|_tj dkr:d|_ n |jƒ|_ dS)NF)rr) rrrrrrr:r;rrr)r!r#r$r$r%r&9s    zSimpleQueue.__init__cCs |jƒ S)N)r;)r!r$r$r%rLBszSimpleQueue.emptycCstj|ƒ|j|j|j|jfS)N)r r'rrrr)r!r$r$r%r(Es zSimpleQueue.__getstate__cCs"|\|_|_|_|_|jj|_dS)N)rrrrr:r;)r!r)r$r$r%r*IszSimpleQueue.__setstate__c Cs&|j�|jjƒ}WdQRXtj|ƒS)N)rrr8rFrG)r!rHr$r$r%rIMszSimpleQueue.getc CsDtj|ƒ}|jdkr"|jj|ƒn|j�|jj|ƒWdQRXdS)N)rFrirrr6)r!r@r$r$r%rCSs   zSimpleQueue.putN) rqrrrsr&rLr(r*rIrCr$r$r$r%r7s  )Ú__all__rrr+r.rEr_rfZqueuerrZ_multiprocessingÚrr Z reductionZForkingPicklerrFÚutilr r r r rÚobjectrrcrrr$r$r$r%Ú s$   b *