ž ÿfíC c @ sl d Z d Z d d l Z d d l Z d d l m Z d d l Z d d l Z d d l m Z m Z d d l m Z d d l Z d d l Z e j ƒ Z d a d d „ Z d Z Gd d „ d e ƒ Z Gd d „ d e ƒ Z Gd d „ d e ƒ Z d d „ Z d d „ Z d d „ Z d a d a d d „ Z Gd d „ d e ƒ Z! Gd d „ d e j" ƒ Z# e j$ e ƒ d S( u+ Implements ProcessPoolExecutor. The follow diagram and text describe the data-flow through the system: |======================= In-process =====================|== Out-of-process ==| +----------+ +----------+ +--------+ +-----------+ +---------+ | | => | Work Ids | => | | => | Call Q | => | | | | +----------+ | | +-----------+ | | | | | ... | | | | ... | | | | | | 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 "Request Q" u" Brian Quinlan (brian@sweetapp.com)i N( u _base( u SimpleQueueu Full( u waitc C sa d a t t j ƒ ƒ } x! | D] \ } } | j d ƒ q Wx | D] \ } } | j ƒ qC Wd S( NT( u Trueu _shutdownu listu _threads_queuesu itemsu putu Noneu join( u itemsu tu q( ( u? /opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu _python_exitK s u _python_exiti c B s | Ee Z d Z d d „ Z d S( u _WorkItemc C s( | | _ | | _ | | _ | | _ d S( N( u futureu fnu argsu kwargs( u selfu futureu fnu argsu kwargs( ( u? /opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu __init__[ s u _WorkItem.__init__N( u __name__u __module__u __qualname__u __init__( u __locals__( ( u? /opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu _WorkItemZ s u _WorkItemc B s&