B /g^*c@sddlZddlZddlZddlmZddlmZgZGdddeZGdddeZ Gd d d eZ Gd d d eZ Gd dde Z GdddejZGddde ZddeeDe_ejdkrLGdddejZGdddejZGdddejZGddde ZGddde ZGd d!d!e Zeeed"Zeed#Zn8Gd$ddejZGd%dde Zd&eiZeed&Zd'd(ZeZd)d*Zd+d,Zd-d.Z dS)/N)process) reductionc@ eZdZdS) ProcessErrorN__name__ __module__ __qualname__r r //usr/lib64/python3.7/multiprocessing/context.pyrrc@r)BufferTooShortNrr r r r r r r c@r) TimeoutErrorNrr r r r rr rc@r)AuthenticationErrorNrr r r r rr rc@sNeZdZeZeZeZeZeej Z eej Z ddZ ddZ dCddZ dd Zd d ZdDd dZdEddZdFddZddZdGddZdHddZdIddZddZdJd d!Zd"d#Zd$d%Zdd&d'd(Zdd&d)d*Zd+d,Zd-d.ZdKd/d0Zd1d2Z d3d4Z!d5d6Z"dLd7d8Z#dMd:d;Z$dNdd?Z'e'j(d@d?Z'dAdBZ)d S)O BaseContextcCs"t}|dkrtdn|SdS)z(Returns the number of CPUs in the systemNzcannot determine number of cpus)os cpu_countZNotImplementedError)selfZnumr r r r(s zBaseContext.cpu_countcCs&ddlm}||d}||S)zReturns a manager associated with a running server process The managers methods such as `Lock()`, `Condition()` and `Queue()` can be used to create shared objects. r) SyncManagerctx)Zmanagersr get_contextZstart)rrZmr r r Manager0s zBaseContext.ManagerTcCddlm}||S)z1Returns two connection object connected by a piper)Pipe) connectionr)rZduplexrr r r r; zBaseContext.PipecCddlm}||dS)z#Returns a non-recursive lock objectr)Lockr) synchronizerr)rrr r r r@rzBaseContext.LockcCr)zReturns a recursive lock objectr)RLockr)rr r)rr r r r r ErzBaseContext.RLockNcCddlm}|||dS)zReturns a condition objectr) Conditionr)rr"r)rlockr"r r r r"JrzBaseContext.ConditionrcCr!)zReturns a semaphore objectr) Semaphorer)rr$r)rvaluer$r r r r$OrzBaseContext.SemaphorecCr!)z"Returns a bounded semaphore objectr)BoundedSemaphorer)rr&r)rr%r&r r r r&TrzBaseContext.BoundedSemaphorecCr)zReturns an event objectr)Eventr)rr'r)rr'r r r r'YrzBaseContext.EventcC ddlm}|||||dS)zReturns a barrier objectr)Barrierr)rr)r)rZpartiesZactionZtimeoutr)r r r r)^rzBaseContext.BarrierrcCr!)Returns a queue objectr)Queuer)queuesr+r)rmaxsizer+r r r r+crzBaseContext.QueuecCr!)r*r) JoinableQueuer)r,r.r)rr-r.r r r r.hrzBaseContext.JoinableQueuecCr)r*r) SimpleQueuer)r,r/r)rr/r r r r/mrzBaseContext.SimpleQueuer cCs"ddlm}||||||dS)zReturns a process pool objectr)Pool)context)Zpoolr0r)rZ processesZ initializerZinitargsZmaxtasksperchildr0r r r r0rs  zBaseContext.PoolcGsddlm}||f|S)zReturns a shared objectr)RawValue) sharedctypesr2)rtypecode_or_typeargsr2r r r r2yrzBaseContext.RawValuecCsddlm}|||S)zReturns a shared arrayr)RawArray)r3r6)rr4size_or_initializerr6r r r r6~rzBaseContext.RawArray)r#cGs&ddlm}||f|||dS)z$Returns a synchronized shared objectr)Valuer#r)r3r8r)rr4r#r5r8r r r r8s  zBaseContext.ValuecCr()z#Returns a synchronized shared arrayr)Arrayr9)r3r:r)rr4r7r#r:r r r r:s zBaseContext.ArraycCs,tjdkr(ttddr(ddlm}|dS)zCheck whether this is a fake forked process in a frozen executable. If so then run code specified by commandline and exit. win32ZfrozenFr)freeze_supportN)sysplatformgetattrspawnr<)rr<r r r r<s zBaseContext.freeze_supportcCsddlm}|S)zZReturn package logger -- if it does not already exist then it is created. r) get_logger)utilrA)rrAr r r rA zBaseContext.get_loggercCr)z8Turn on logging and add a handler which prints to stderrr) log_to_stderr)rBrD)rZlevelrDr r r rDrzBaseContext.log_to_stderrcCsddlm}dS)zVInstall support for sending connections and sockets between processes r)rN)r)rrr r r allow_connection_picklingsz%BaseContext.allow_connection_picklingcCddlm}||dS)zSets the path to a python.exe or pythonw.exe binary used to run child processes instead of sys.executable when using the 'spawn' start method. Useful for people embedding Python. r)set_executableN)r@rH)rZ executablerHr r r rHs zBaseContext.set_executablecCrG)zkSet list of module names to try to load in forkserver process. This is really just a hint. r)set_forkserver_preloadN) forkserverrI)rZ module_namesrIr r r rIrCz"BaseContext.set_forkserver_preloadcCsH|dkr |Sy t|}Wn"tk r:td|dYnX||S)Nzcannot find context for %r)_concrete_contextsZKeyError ValueError_check_available)rmethodrr r r rs zBaseContext.get_contextFcCs|jSN)_namerZ allow_noner r r get_start_methodzBaseContext.get_start_methodcCs tddS)Nz+cannot set start method of concrete context)rLrrNZforcer r r set_start_methodrSzBaseContext.set_start_methodcCs tdS)z_Controls how objects will be reduced to a form that can be shared with other processes.r)globalsZgetrr r r reducerszBaseContext.reducercCs|td<dS)Nr)rV)rrr r r rXcCsdSrOr rWr r r rMrSzBaseContext._check_available)TrOrrZ)NNrr[)NNr NrOrOFr\)*rrr rr rr staticmethodrZcurrent_processZactive_childrenrrrrr r"r$r&r'r)r+r.r/r0r2r6r8r:r<rArDrFrHrIrrRrUZpropertyrXZsetterrMr r r r rsJ              rc@seZdZdZeddZdS)ProcessNcCstj|SrO)_default_contextrr^_Popen) process_objr r r r`rYzProcess._Popenrrr Z _start_methodr]r`r r r r r^r^csFeZdZeZddZd fdd ZdddZdd d Zd d ZZ S)DefaultContextcCs||_d|_dSrO)r__actual_context)rr1r r r __init__zDefaultContext.__init__Ncs0|dkr |jdkr|j|_|jSt|SdSrO)rer_Zsuperr)rrNZ __class__r r rs  zDefaultContext.get_contextFcCs<|jdk r|std|dkr,|r,d|_dS|||_dS)Nzcontext has already been set)re RuntimeErrorrrTr r r rUs  zDefaultContext.set_start_methodcCs"|jdkr|rdS|j|_|jjSrO)rer_rPrQr r r rRs  zDefaultContext.get_start_methodcCs,tjdkrdgStjr dddgSddgSdS)Nr;r@forkrJ)r=r>rHAVE_SEND_HANDLErWr r r get_all_start_methodss   z$DefaultContext.get_all_start_methodsrOr\r\) rrr r^rfrrUrRrlZ __classcell__r r rhr rds   rdcCsg|]}|ddkr|qS)rZ_r )Z.0Zxr r r srmr;c@eZdZdZeddZdS) ForkProcessrjcCddlm}||SNr)Popen)Z popen_forkrrrarrr r r r`rzForkProcess._PopenNrbr r r r rorcroc@rn) SpawnProcessr@cCrprq)Zpopen_spawn_posixrrrsr r r r`rSpawnProcess._PopenNrbr r r r rtrcrtc@rn)ForkServerProcessrJcCrprq)Zpopen_forkserverrrrsr r r r` rzForkServerProcess._PopenNrbr r r r rvrcrvc@eZdZdZeZdS) ForkContextrjN)rrr rPror^r r r r rx%rcrxc@rw SpawnContextr@Nrrr rPrtr^r r r r rz)rcrzc@seZdZdZeZddZdS)ForkServerContextrJcCstjstddS)Nz%forkserver start method not available)rrkrLrWr r r rM0rgz"ForkServerContext._check_availableN)rrr rPrvr^rMr r r r r|-sr|)rjr@rJrjc@rn)rtr@cCrprq)Zpopen_spawn_win32rrrsr r r r`?rruNrbr r r r rt=rcc@rwryr{r r r r rzDrcr@cCst|t_dSrO)rKr_re)rNr r r _force_start_methodQrSr}cCs ttddS)Nspawning_popen)r?_tlsr r r r get_spawning_popenZrSrcCs |t_dSrO)rr~)Zpopenr r r set_spawning_popen]rSrcCs tdkrtdt|jdS)NzF%s objects should only be shared between processes through inheritance)rriZtyper)Zobjr r r assert_spawning`s r)!rr=Z threadingrErrZ__all__Z Exceptionrr rrZobjectrZ BaseProcessr^rdZdirr>rortrvrxrzr|rKr_r}Zlocalrrrrr r r r ZsD  >'