U e5dzn ã @ s” d Z dZddlZddlZddlmZ ddlZddlmZ ddlZ ddl ZddlmZ ddl Z ddlZddlmZ ddlZddlZddlZe ¡ ZdaG d d „ d ƒZdd„ Zd ZdZG dd„ deƒZG dd„ dƒZdd„ ZG dd„ deƒZ G dd„ deƒZ!G dd„ deƒZ"G dd„ deƒZ#dd„ Z$dd „ Z%d1d!d"„Z&d#d$„ Z'd%d&„ Z(d'd(„ Z)da*da+d)d*„ Z,d+d,„ Z-G d-d.„ d.ej.ƒZ/G d/d0„ d0ej0ƒZ1e 2e¡ dS )2a- 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)ÚFull)ÚQueue)ÚpartialFc @ s, e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd S ) Ú _ThreadWakeupc C s t jdd�\| _| _d S )NF)Zduplex)ÚmpZPipeÚ_readerÚ_writer©Úself© r ú2/usr/lib64/python3.8/concurrent/futures/process.pyÚ__init__R s z_ThreadWakeup.__init__c C s | j ¡ | j ¡ d S ©N)r Úcloser r r r r r U s z_ThreadWakeup.closec C s | j d¡ d S )Nó )r Z send_bytesr r r r ÚwakeupY s z_ThreadWakeup.wakeupc C s | j ¡ r| j ¡ q d S r )r ZpollZ recv_bytesr r r r Úclear\ s z_ThreadWakeup.clearN)Ú__name__Ú __module__Ú__qualname__r r r r r r r r r Q s r c C s@ da tt ¡ ƒ} | D ]\}}| ¡ q| D ]\}}| ¡ q*d S ©NT)Ú_global_shutdownÚlistÚ_threads_wakeupsÚitemsr Újoin)r Ú_Ú thread_wakeupÚtr r r Ú_python_exita s r é é= c @ s e Zd Zdd„ Zdd„ ZdS )Ú_RemoteTracebackc C s || _ d S r ©Útb)r r% r r r r z s z_RemoteTraceback.__init__c C s | j S r r$ r r r r Ú__str__| s z_RemoteTraceback.__str__N)r r r r r&