/usr/lib64/python3.9/concurrent/futures/__pycache__
NameSizeModeActions
process.cpython-39.opt-1.pyc212290644editdlrm
process.cpython-39.opt-2.pyc158730644editdlrm
process.cpython-39.pyc213960644editdlrm
thread.cpython-39.opt-1.pyc59060644editdlrm
thread.cpython-39.opt-2.pyc53600644editdlrm
thread.cpython-39.pyc59060644editdlrm
_base.cpython-39.opt-1.pyc224360644editdlrm
_base.cpython-39.opt-2.pyc143940644editdlrm
_base.cpython-39.pyc224360644editdlrm
__init__.cpython-39.opt-1.pyc11100644editdlrm
__init__.cpython-39.opt-2.pyc10340644editdlrm
__init__.cpython-39.pyc11100644editdlrm
Edit: /usr/lib64/python3.9/concurrent/futures/__pycache__/process.cpython-39.opt-1.pyc (21229B)
a ´i£zã@s‚dZdZddlZddlmZddlZddlZddlZddl m Z ddl Z ddl Z ddl mZddlZddlZddlZe  ¡ZdaGdd „d ƒZd d „Ze  e¡d Zd ZGdd„deƒZGdd„dƒZdd„ZGdd„deƒZGdd„deƒZ Gdd„deƒZ!Gdd„de ƒZ"dd„Z#dd„Z$d.d d!„Z%d"d#„Z&Gd$d%„d%e j'ƒZ(da)da*d&d'„Z+d(d)„Z,Gd*d+„d+ej-ƒZ.Gd,d-„d-ej/ƒZ0dS)/a- Implements ProcessPoolExecutor. The following diagram and text describe the data-flow through the system: |======================= In-process =====================|== Out-of-process ==| +----------+ +----------+ +--------+ +-----------+ +---------+ | | => | Work Ids | | | | Call Q | | Process | | | +----------+ | | +-----------+ | Pool | | | | ... | | | | ... | +---------+ | | | 6 | => | | => | 5, call() | => | | | | | 7 | | | | ... | | | | Process | | ... | | Local | +-----------+ | Process | | Pool | +----------+ | Worker | | #1..n | | Executor | | Thread | | | | | +----------- + | | +-----------+ | | | | <=> | Work Items | <=> | | <= | Result Q | <= | | | | +------------+ | | +-----------+ | | | | | 6: call() | | | | ... | | | | | | future | | | | 4, result | | | | | | ... | | | | 3, except | | | +----------+ +------------+ +--------+ +-----------+ +---------+ Executor.submit() called: - creates a uniquely numbered _WorkItem and adds it to the "Work Items" dict - adds the id of the _WorkItem to the "Work Ids" queue Local worker thread: - reads work ids from the "Work Ids" queue and looks up the corresponding WorkItem from the "Work Items" dict: if the work item has been cancelled then it is simply removed from the dict, otherwise it is repackaged as a _CallItem and put in the "Call Q". New _CallItems are put in the "Call Q" until "Call Q" is full. NOTE: the size of the "Call Q" is kept small because calls placed in the "Call Q" can no longer be cancelled with Future.cancel(). - reads _ResultItems from "Result Q", updates the future stored in the "Work Items" dict and deletes the dict entry Process #1..n: - reads _CallItems from "Call Q", executes the calls, and puts the resulting _ResultItems in "Result Q" z"Brian Quinlan (brian@sweetapp.com)éN)Ú_base)ÚQueue)ÚpartialFc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú _ThreadWakeupcCsd|_tjdd�\|_|_dS)NF)Úduplex)Ú_closedÚmpÚPipeÚ_readerÚ_writer©Úself©rú2/usr/lib64/python3.9/concurrent/futures/process.pyÚ__init__Csz_ThreadWakeup.__init__cCs$|js d|_|j ¡|j ¡dS©NT)rr Úcloser r rrrrGs z_ThreadWakeup.closecCs|js|j d¡dS)Nó)rr Ú send_bytesr rrrÚwakeupMsz_ThreadWakeup.wakeupcCs |js|j ¡r|j ¡qdS©N)rr ÚpollÚ recv_bytesr rrrÚclearQs z_ThreadWakeup.clearN)Ú__name__Ú __module__Ú __qualname__rrrrrrrrrBsrcCs@datt ¡ƒ}|D]\}}| ¡q|D]\}}| ¡q*dSr)Ú_global_shutdownÚlistÚ_threads_wakeupsÚitemsrÚjoin)r Ú_Ú thread_wakeupÚtrrrÚ _python_exitWs     r%éé=c@seZdZdd„Zdd„ZdS)Ú_RemoteTracebackcCs ||_dSr©Útb)r r*rrrrwsz_RemoteTraceback.__init__cCs|jSrr)r rrrÚ__str__ysz_RemoteTraceback.__str__N)rrrrr+rrrrr(vsr(c@seZdZdd„Zdd„ZdS)Ú_ExceptionWithTracebackcCs8t t|ƒ||¡}d |¡}||_d|j_d||_dS)NÚz """ %s""")Ú tracebackÚformat_exceptionÚtyper!ÚexcÚ __traceback__r*)r r1r*rrrr}s  z _ExceptionWithTraceback.__init__cCst|j|jffSr)Ú _rebuild_excr1r*r rrrÚ __reduce__…sz"_ExceptionWithTraceback.__reduce__N)rrrrr4rrrrr,|sr,cCst|ƒ|_|Sr)r(Ú __cause__)r1r*rrrr3ˆs r3c@seZdZdd„ZdS)Ú _WorkItemcCs||_||_||_||_dSr)ÚfutureÚfnÚargsÚkwargs)r r7r8r9r:rrrr�sz_WorkItem.__init__N©rrrrrrrrr6Œsr6c@seZdZddd„ZdS)Ú _ResultItemNcCs||_||_||_dSr)Úwork_idÚ exceptionÚresult)r r=r>r?rrrr”sz_ResultItem.__init__)NNr;rrrrr<“sr<c@seZdZdd„ZdS)Ú _CallItemcCs||_||_||_||_dSr)r=r8r9r:)r r=r8r9r:rrrršsz_CallItem.__init__Nr;rrrrr@™sr@cs.eZdZdZd‡fdd„ Z‡fdd„Z‡ZS)Ú _SafeQueuez=Safe Queue set exception to the future object linked to a jobrcs&||_||_||_tƒj||d�dS)N)Úctx)Úpending_work_itemsÚ shutdown_lockr#Úsuperr)r Úmax_sizerBrCrDr#©Ú __class__rrr£sz_SafeQueue.__init__csœt|tƒrŠt t|ƒ||j¡}td d |¡¡ƒ|_ |j   |j d¡}|j �|j ¡Wdƒn1sj0Y|dur˜|j |¡ntƒ ||¡dS)Nz """ {}"""r-)Ú isinstancer@r.r/r0r2r(Úformatr!r5rCÚpopr=rDr#rr7Ú set_exceptionrEÚ_on_queue_feeder_error)r ÚeÚobjr*Ú work_itemrGrrrMªs (z!_SafeQueue._on_queue_feeder_error)r)rrrÚ__doc__rrMÚ __classcell__rrrGrrA¡srAcgs,t|Ž}tt ||¡ƒ}|s dS|VqdS)z, Iterates over zip()ed iterables in chunks. N)ÚzipÚtupleÚ itertoolsÚislice)Ú chunksizeÚ iterablesÚitÚchunkrrrÚ _get_chunksºs r[cs‡fdd„|DƒS)z¼ Processes a chunk of an iterable passed to map. Runs the function passed to map() on a chunk of the iterable passed to map. This function is run in a separate process. csg|] }ˆ|Ž‘qSrr)Ú.0r9©r8rrÚ Írz"_process_chunk..r)r8rZrr]rÚ_process_chunkÄs r_c Cs`z| t|||d�¡WnBtyZ}z*t||jƒ}| t||d�¡WYd}~n d}~00dS)z.Safely send back the given result or exception)r?r>©r>N)Úputr<Ú BaseExceptionr,r2)Ú result_queuer=r?r>rNr1rrrÚ_sendback_resultÐs ÿ  rdc CsÔ|dur:z ||ŽWn$ty8tjjddd�YdS0|jdd�}|dur`| t ¡¡dSz|j|j i|j ¤Ž}Wn@ty¸}z(t ||j ƒ}t ||j|d�WYd}~nd}~00t ||j|d�~~q:dS)a¼Evaluates calls from call_queue and places the results in result_queue. This worker is run in a separate process. Args: call_queue: A ctx.Queue of _CallItems that will be read and evaluated by the worker. result_queue: A ctx.Queue of _ResultItems that will written to by the worker. initializer: A callable initializer, or None initargs: A tuple of args for the initializer NzException in initializer:T)Úexc_info©Úblockr`)r?)rbrÚLOGGERÚcriticalÚgetraÚosÚgetpidr8r9r:r,r2rdr=)Ú call_queuercÚ initializerÚinitargsÚ call_itemÚrrNr1rrrÚ_process_workerÚs$     &rrcspeZdZdZ‡fdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Z‡ZS)Ú_ExecutorManagerThreadatManages the communication between this process and the worker processes. The manager is run in a local thread. Args: executor: A reference to the ProcessPoolExecutor that owns this thread. A weakref will be own by the manager as well as references to internal objects used to introspect the state of the executor. csf|j|_|j|_|j|jfdd„}t ||¡|_|j|_|j |_ |j |_ |j |_|j|_tƒ ¡dS)NcSs<tj d¡|�| ¡Wdƒn1s.0YdS)Nz?Executor collected: triggering callback for QueueManager wakeup)rÚutilÚdebugr)r"r#rDrrrÚ weakref_cbs z3_ExecutorManagerThread.__init__..weakref_cb)Ú_executor_manager_thread_wakeupr#Ú_shutdown_lockrDÚweakrefÚrefÚexecutor_referenceÚ _processesÚ processesÚ _call_queuermÚ _result_queuercÚ _work_idsÚwork_ids_queueÚ_pending_work_itemsrCrEr)r ÚexecutorrvrGrrrs þ z_ExecutorManagerThread.__init__cCs€| ¡| ¡\}}}|r(| |¡dS|durX| |¡~| ¡}|durV|j ¡~| ¡r| ¡|j s|  ¡dSqdSr) Úadd_call_item_to_queueÚwait_result_broken_or_wakeupÚterminate_brokenÚprocess_result_itemr{Ú_idle_worker_semaphoreÚreleaseÚis_shutting_downÚflag_executor_shutting_downrCÚjoin_executor_internals)r Ú result_itemÚ is_brokenÚcauserƒrrrÚrun:s"   z_ExecutorManagerThread.runcCs~|j ¡rdSz|jjdd�}Wntjy6YdS0|j|}|j ¡rn|jj t ||j |j |j ƒdd�q|j|=qqdS)NFrfT)rmÚfullr�rjÚqueueÚEmptyrCr7Úset_running_or_notify_cancelrar@r8r9r:)r r=rPrrrr„Zs"    ýüz-_ExecutorManagerThread.add_call_item_to_queuec Csæ|jj}|jj}||g}dd„t|j ¡ƒDƒ}tj ||¡}d}d}d}||vr z|  ¡}d}Wq¬t yœ} z t   t | ƒ| | j¡}WYd} ~ q¬d} ~ 00n ||vr¬d}|j�|j ¡Wdƒn1sÒ0Y|||fS)NcSsg|] }|j‘qSr)Úsentinel©r\Úprrrr^{rzG_ExecutorManagerThread.wait_result_broken_or_wakeup..TF)rcr r#rr}ÚvaluesrÚ connectionÚwaitÚrecvrbr.r/r0r2rDr) r Ú result_readerÚ wakeup_readerÚreadersÚworker_sentinelsÚreadyr�rŽr�rNrrrr…qs&,(z3_ExecutorManagerThread.wait_result_broken_or_wakeupcCsrt|tƒr2|j |¡}| ¡|jsn| ¡dSn<|j |jd¡}|durn|jr`|j   |j¡n|j   |j ¡dSr) rIÚintr}rKr!rŒrCr=r>r7rLÚ set_resultr?)r r�r—rPrrrr‡�s  z*_ExecutorManagerThread.process_result_itemcCs| ¡}tp|dup|jSr)r{rÚ_shutdown_thread)r rƒrrrrЧs ÿz'_ExecutorManagerThread.is_shutting_downcCs˜| ¡}|dur d|_d|_d}tdƒ}|durHtdd |¡›d�ƒ|_|j ¡D]\}}|j   |¡~qR|j  ¡|j   ¡D] }| ¡q~| ¡dS)NzKA child process terminated abruptly, the process pool is not usable anymoreTz^A process in the process pool was terminated abruptly while the future was running or pending.z ''' r-z''')r{Ú_brokenr£ÚBrokenProcessPoolr(r!r5rCr r7rLrr}r˜Ú terminaterŒ)r r�rƒÚbper=rPr—rrrr†±s"ÿ   z'_ExecutorManagerThread.terminate_brokencCs€| ¡}|dur|d|_|jr|i}|j ¡D]\}}|j ¡s*|||<q*||_z|j ¡WqLt j yrYqvYqL0qLd|_dS)NTF) r{r£Ú_cancel_pending_futuresrCr r7Úcancelr�Ú get_nowaitr’r“)r rƒÚnew_pending_work_itemsr=rPrrrr‹×s   z2_ExecutorManagerThread.flag_executor_shutting_downc Csl| ¡}d}||krh| ¡dkrht||ƒD]8}z|j d¡|d7}Wq,tjybYq Yq,0q,q dS)Nrr&)Úget_n_children_aliveÚrangermÚ put_nowaitr’ÚFull)r Ún_children_to_stopÚn_sentinels_sentÚirrrÚshutdown_workersñs ÿ  z'_ExecutorManagerThread.shutdown_workerscCsh| ¡|j ¡|j ¡|j�|j ¡Wdƒn1sB0Y|j ¡D] }| ¡qVdSr) r³rmrÚ join_threadrDr#r}r˜r!©r r—rrrrŒÿs  (z._ExecutorManagerThread.join_executor_internalscCstdd„|j ¡DƒƒS)Ncss|]}| ¡VqdSr)Úis_aliver–rrrÚ rz>_ExecutorManagerThread.get_n_children_alive..)Úsumr}r˜r rrrr¬ sz+_ExecutorManagerThread.get_n_children_alive)rrrrQrr�r„r…r‡rŠr†r‹r³rŒr¬rRrrrGrrss +  & rsc Cshtrtrttƒ‚dazt d¡}Wnttfy:YdS0|dkrHdS|dkrTdSd|attƒ‚dS)NTÚSC_SEM_NSEMS_MAXéÿÿÿÿéz@system provides too few semaphores (%d available, 256 necessary))Ú_system_limits_checkedÚ_system_limitedÚNotImplementedErrorrkÚsysconfÚAttributeErrorÚ ValueError)Ú nsems_maxrrrÚ_check_system_limitss ÿrÃccs&|D]}| ¡|r| ¡VqqdS)z½ Specialized implementation of itertools.chain.from_iterable. Each item in *iterable* should be a list. This function is careful not to keep references to yielded objects. N)ÚreverserK)ÚiterableÚelementrrrÚ_chain_from_iterable_of_lists,srÇc@seZdZdZdS)r¥zy Raised when a process in a ProcessPoolExecutor terminated abruptly while a future was in the running state. N)rrrrQrrrrr¥8sr¥cs~eZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Ze j jj e_ dddœ‡fdd„ Z dddœdd„Z e j j j e _ ‡ZS)ÚProcessPoolExecutorNrcCsJtƒ|dur6t ¡pd|_tjdkrntt|jƒ|_n8|dkrHtdƒ‚n tjdkrh|tkrhtdt›�ƒ‚||_|dur~t   ¡}||_ |j j dd�d k|_ |dur°t|ƒs°td ƒ‚||_||_d|_i|_d|_t ¡|_t d¡|_d|_d|_i|_d|_tƒ|_|jt }t!||j |j|j|jd �|_"d |j"_#| $¡|_%t& '¡|_(dS) aSInitializes a new ProcessPoolExecutor instance. Args: max_workers: The maximum number of processes that can be used to execute the given calls. If None or not given then as many worker processes will be created as the machine has processors. mp_context: A multiprocessing context to launch the workers. This object should provide SimpleQueue, Queue and Process. initializer: A callable used to initialize worker processes. initargs: A tuple of arguments to pass to the initializer. Nr&Úwin32rz"max_workers must be greater than 0zmax_workers must be <= F)Ú allow_noneÚforkzinitializer must be a callable)rFrBrCrDr#T))rÃrkÚ cpu_countÚ _max_workersÚsysÚplatformÚminÚ_MAX_WINDOWS_WORKERSrÁrÚ get_contextÚ _mp_contextÚget_start_methodÚ#_safe_to_dynamically_spawn_childrenÚcallableÚ TypeErrorÚ _initializerÚ _initargsÚ_executor_manager_threadr|r£Ú threadingÚLockrxÚ Semaphorerˆr¤Ú _queue_countr‚r¨rrwÚEXTRA_QUEUED_CALLSrAr~Ú _ignore_epipeÚ SimpleQueuerr’rr€)r Ú max_workersÚ mp_contextrnroÚ queue_sizerrrr@sZ  ÿ  ÿÿÿ    ü zProcessPoolExecutor.__init__cCs<|jdur8|js| ¡t|ƒ|_|j ¡|jt|j<dSr)rÚrÕÚ_launch_processesrsÚstartrwrr rrrÚ_start_executor_manager_thread•s   ÿz2ProcessPoolExecutor._start_executor_manager_threadcCs2|jjdd�rdSt|jƒ}||jkr.| ¡dS)NF)Úblocking)rˆÚacquireÚlenr|rÍÚ_spawn_process)r Ú process_countrrrÚ_adjust_process_countŸs   z)ProcessPoolExecutor._adjust_process_countcCs$tt|jƒ|jƒD] }| ¡qdSr)r­rêr|rÍrë)r r"rrrrå®sz%ProcessPoolExecutor._launch_processescCs8|jjt|j|j|j|jfd�}| ¡||j|j <dS)N)Útargetr9) rÓÚProcessrrr~rrØrÙrær|Úpidrµrrrrë¶sýþz"ProcessPoolExecutor._spawn_processcOs¶|j�œ|jrt|jƒ‚|jr&tdƒ‚tr2tdƒ‚t ¡}t||||ƒ}||j |j <|j   |j ¡|j d7_ |j  ¡|jrˆ| ¡| ¡|WdƒS1s¨0YdS)Nz*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdownr&)rxr¤r¥r£Ú RuntimeErrorrrÚFuturer6r‚rÞr€rarwrrÕrírç)r r8r9r:ÚfÚwrrrÚsubmitÀs"   zProcessPoolExecutor.submitr&)ÚtimeoutrWcs:|dkrtdƒ‚tƒjtt|ƒt|d|iŽ|d�}t|ƒS)ajReturns an iterator equivalent to map(fn, iter). Args: fn: A callable that will take as many arguments as there are passed iterables. timeout: The maximum number of seconds to wait. If None, then there is no limit on the wait time. chunksize: If greater than one, the iterables will be chopped into chunks of size chunksize and submitted to the process pool. If set to one, the items in the list will be sent one at a time. Returns: An iterator equivalent to: map(func, *iterables) but the calls may be evaluated out-of-order. Raises: TimeoutError: If the entire result iterator could not be generated before the given timeout. Exception: If fn(*args) raises for any values. r&zchunksize must be >= 1.rW)rö)rÁrEÚmaprr_r[rÇ)r r8rörWrXÚresultsrGrrr÷Ùs þzProcessPoolExecutor.mapTF)Úcancel_futurescCs˜|j�0||_d|_|jdur(|j ¡Wdƒn1s<0Y|jdur^|r^|j ¡d|_d|_|jdur‚|r‚|j  ¡d|_d|_ d|_dSr) rxr¨r£rwrrÚr!r~rrr|)r ršrùrrrÚshutdownös (  zProcessPoolExecutor.shutdown)NNNr)T)rrrrrçrírårërõrÚExecutorrQr÷rúrRrrrGrrÈ?sÿ U   rÈ)NN)1rQÚ __author__rkÚconcurrent.futuresrr’ÚmultiprocessingrÚmultiprocessing.connectionÚmultiprocessing.queuesrrÛryÚ functoolsrrUrÎr.ÚWeakKeyDictionaryrrrr%Ú_register_atexitrßrÑÚ Exceptionr(r,r3Úobjectr6r<r@rAr[r_rdrrÚThreadrsr¼r½rÃrÇÚBrokenExecutorr¥rûrÈrrrrÚsP*       )