o w[eM-@sddlZddlZddlZddlmZddlmZdZGdddeZGdd d eZ Gd d d eZ Gd d d eZ Gddde Z GdddejZGddde ZejdkrGdddejZGdddejZGdddejZGddde ZGddde ZGdd d e Zeeed!Zejd"kreed#Zn#eed$ZnGd%ddejZGd&dde Zd#eiZeed#Zd'd(ZeZd)d*Zd+d,Zd-d.ZdS)/N)process) reductionc@ eZdZdS) ProcessErrorN__name__ __module__ __qualname__rrr./usr/lib/python3.10/multiprocessing/context.pyrrc@r)BufferTooShortNrrrrr rr rc@r) TimeoutErrorNrrrrr rr rc@r)AuthenticationErrorNrrrrr rr rc@s\eZdZeZeZeZeZeej Z eej Z eej Z ddZ ddZ dCddZdd Zd d ZdDd dZdEddZdEddZddZdFddZdGddZdGddZddZ  dHd d!Zd"d#Zd$d%Zdd&d'd(Zdd&d)d*Zd+d,Zd-d.ZdDd/d0Z d1d2Z!d3d4Z"d5d6Z#dDd7d8Z$dId:d;Z%dIdd?Z(e(j)d@d?Z(dAdBZ*d S)J BaseContextcCst}|dur td|S)z(Returns the number of CPUs in the systemNzcannot determine number of cpus)os cpu_countNotImplementedError)selfnumrrr r)szBaseContext.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)managersr get_contextstart)rrmrrr Manager1s zBaseContext.ManagerTcCddlm}||S)z1Returns two connection object connected by a piper)Pipe) connectionr )rduplexr rrr r < zBaseContext.PipecCddlm}||dS)z#Returns a non-recursive lock objectr)Lockr) synchronizer%r)rr%rrr r%A zBaseContext.LockcCr$)zReturns a recursive lock objectr)RLockr)r&r(r)rr(rrr r(Fr'zBaseContext.RLockNcCddlm}|||dS)zReturns a condition objectr) Conditionr)r&r*r)rlockr*rrr r*K zBaseContext.ConditionrcCr))zReturns a semaphore objectr) Semaphorer)r&r-r)rvaluer-rrr r-Pr,zBaseContext.SemaphorecCr))z"Returns a bounded semaphore objectr)BoundedSemaphorer)r&r/r)rr.r/rrr r/Ur,zBaseContext.BoundedSemaphorecCr$)zReturns an event objectr)Eventr)r&r0r)rr0rrr r0Zr'zBaseContext.EventcC ddlm}|||||dS)zReturns a barrier objectr)Barrierr)r&r2r)rpartiesactiontimeoutr2rrr r2_s zBaseContext.BarrierrcCr))Returns a queue objectr)Queuer)queuesr7r)rmaxsizer7rrr r7dr,zBaseContext.QueuecCr))r6r) JoinableQueuer)r8r:r)rr9r:rrr r:ir,zBaseContext.JoinableQueuecCr$)r6r) SimpleQueuer)r8r;r)rr;rrr r;nr'zBaseContext.SimpleQueuercCs"ddlm}||||||dS)zReturns a process pool objectr)Pool)context)poolr<r)r processes initializerinitargsmaxtasksperchildr<rrr r<ss  zBaseContext.PoolcGsddlm}||g|RS)zReturns a shared objectr)RawValue) sharedctypesrC)rtypecode_or_typeargsrCrrr rCzr,zBaseContext.RawValuecCsddlm}|||S)zReturns a shared arrayr)RawArray)rDrG)rrEsize_or_initializerrGrrr rGs  zBaseContext.RawArray)r+cGs(ddlm}||g|R||dS)z$Returns a synchronized shared objectr)Valuer+r)rDrIr)rrEr+rFrIrrr rIs zBaseContext.ValuecCr1)z#Returns a synchronized shared arrayr)ArrayrJ)rDrKr)rrErHr+rKrrr rKs zBaseContext.ArraycCs4tjdkrttddrddlm}|dSdSdS)zCheck whether this is a fake forked process in a frozen executable. If so then run code specified by commandline and exit. win32frozenFr)freeze_supportN)sysplatformgetattrspawnrN)rrNrrr rNs  zBaseContext.freeze_supportcCsddlm}|S)zZReturn package logger -- if it does not already exist then it is created. r) get_logger)utilrS)rrSrrr rSs zBaseContext.get_loggercCr)z8Turn on logging and add a handler which prints to stderrr) log_to_stderr)rTrU)rlevelrUrrr rUr#zBaseContext.log_to_stderrcCsddlm}dS)zVInstall support for sending connections and sockets between processes r)r!N)r!)rr!rrr 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)rRrZ)r executablerZrrr rZs  zBaseContext.set_executablecCrY)zkSet list of module names to try to load in forkserver process. This is really just a hint. r)set_forkserver_preloadN) forkserverr\)r module_namesr\rrr r\s  z"BaseContext.set_forkserver_preloadcCsB|dur|Szt|}Wntytd|dw||S)Nzcannot find context for %r)_concrete_contextsKeyError ValueError_check_available)rmethodrrrr rs  zBaseContext.get_contextFcCs|jSN)_namer allow_nonerrr get_start_methodszBaseContext.get_start_methodcCstd)Nz+cannot set start method of concrete context)rarrcforcerrr set_start_methodszBaseContext.set_start_methodcCs tdS)z_Controls how objects will be reduced to a form that can be shared with other processes.r)globalsgetrrrr reducers zBaseContext.reducercCs|td<dS)Nr)rl)rrrrr rocCdSrdrrnrrr rbszBaseContext._check_available)Trd)r)NN)r)NNrNF)+r r r rrrr staticmethodrcurrent_processparent_processactive_childrenrrr r%r(r*r-r/r0r2r7r:r;r<rCrGrIrKrNrSrUrXrZr\rrhrkpropertyrosetterrbrrrr rsT                 rc@s(eZdZdZeddZeddZdS)ProcessNcCstj|Srd)_default_contextrry_Popen) process_objrrr r{szProcess._PopencCstjSrd)rzrry _after_forkrrrr r}rpzProcess._after_forkr r r _start_methodrsr{r}rrrr rys  rycsFeZdZeZddZd fdd ZdddZdd d Zd d ZZ S)DefaultContextcCs||_d|_dSrd)rz_actual_context)rr=rrr __init__s zDefaultContext.__init__Ncs,|dur|jdur |j|_|jSt|Srd)rrzsuperr)rrc __class__rr rs   zDefaultContext.get_contextFcCs<|jdur |s td|dur|rd|_dS|||_dS)Nzcontext has already been set)r RuntimeErrorrrirrr rks  zDefaultContext.set_start_methodcCs"|jdur |r dS|j|_|jjSrd)rrzrerfrrr rhs zDefaultContext.get_start_methodcCs>tjdkrdgStjdkrddgnddg}tjr|d|S)NrLrRdarwinforkr])rOrPrHAVE_SEND_HANDLEappend)rmethodsrrr get_all_start_methodss  z$DefaultContext.get_all_start_methodsrdrr) r r r ryrrrkrhr __classcell__rrrr rs  rrLc@eZdZdZeddZdS) ForkProcessrcCddlm}||SNr)Popen) popen_forkrr|rrrr r{r#zForkProcess._PopenNr r r rrsr{rrrr rrc@(eZdZdZeddZeddZdS) SpawnProcessrRcCrr)popen_spawn_posixrrrrr r{r#SpawnProcess._PopencCrqrdrrrrr r}"SpawnProcess._after_forkNr~rrrr r  rc@r)ForkServerProcessr]cCrr)popen_forkserverrrrrr r{)r#zForkServerProcess._PopenNrrrrr r'rrc@eZdZdZeZdS) ForkContextrN)r r r rerryrrrr r.rc@r SpawnContextrRNr r r rerryrrrr r2rrc@seZdZdZeZddZdS)ForkServerContextr]cCstjstddS)Nz%forkserver start method not available)rrrarnrrr rb9sz"ForkServerContext._check_availableN)r r r rerryrbrrrr r6s r)rrRr]rrRrc@r)rrRcCrr)popen_spawn_win32rrrrr r{Mr#rcCrqrdrrrrr r}RrrNr~rrrr rKrc@rrrrrrr rWrcCst|t_dSrd)r_rzr)rcrrr _force_start_methoddsrcCs ttddS)Nspawning_popen)rQ_tlsrrrr get_spawning_popenms rcCs |t_dSrd)rr)popenrrr set_spawning_popenps rcCs tdurtdt|jdS)NzF%s objects should only be shared between processes through inheritance)rrtyper )objrrr assert_spawningss r) rrO threadingrWrr__all__ Exceptionrrrrobjectr BaseProcessryrrPrrrrrrr_rzrlocalrrrrrrrr sL  ? ,