o ?OgM-@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>/opt/alt/python310/lib64/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)selfZnumrrr 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)Zmanagersr get_contextstart)rrmrrr Manager1s zBaseContext.ManagerTcCddlm}||S)z1Returns two connection object connected by a piper)Pipe) connectionr)rZduplexrrrr 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#r-r)rr-rrr r-Zr$zBaseContext.EventcC ddlm}|||||dS)zReturns a barrier objectr)Barrierr)r#r/r)rZpartiesactionZtimeoutr/rrr r/_s zBaseContext.BarrierrcCr&)Returns a queue objectr)Queuer)queuesr2r)rmaxsizer2rrr r2dr)zBaseContext.QueuecCr&)r1r) JoinableQueuer)r3r5r)rr4r5rrr r5ir)zBaseContext.JoinableQueuecCr!)r1r) SimpleQueuer)r3r6r)rr6rrr r6nr$zBaseContext.SimpleQueuercCs"ddlm}||||||dS)zReturns a process pool objectr)Pool)context)Zpoolr7r)rZ processesZ initializerZinitargsZmaxtasksperchildr7rrr r7ss  zBaseContext.PoolcGsddlm}||g|RS)zReturns a shared objectr)RawValue) sharedctypesr9)rtypecode_or_typeargsr9rrr r9zr)zBaseContext.RawValuecCsddlm}|||S)zReturns a shared arrayr)RawArray)r:r=)rr;size_or_initializerr=rrr r=s  zBaseContext.RawArray)r(cGs(ddlm}||g|R||dS)z$Returns a synchronized shared objectr)Valuer(r)r:r?r)rr;r(r<r?rrr r?s zBaseContext.ValuecCr.)z#Returns a synchronized shared arrayr)Arrayr@)r:rAr)rr;r>r(rArrr rAs 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)sysplatformgetattrspawnrD)rrDrrr rDs  zBaseContext.freeze_supportcCsddlm}|S)zZReturn package logger -- if it does not already exist then it is created. r) get_logger)utilrI)rrIrrr rIs zBaseContext.get_loggercCr)z8Turn on logging and add a handler which prints to stderrr) log_to_stderr)rJrK)rlevelrKrrr rKr zBaseContext.log_to_stderrcCsddlm}dS)zVInstall support for sending connections and sockets between processes r)rN)r)rrrrr 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)rHrP)r executablerPrrr rPs  zBaseContext.set_executablecCrO)zkSet list of module names to try to load in forkserver process. This is really just a hint. r)set_forkserver_preloadN) forkserverrR)rZ module_namesrRrrr rRs  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)_namerZ allow_nonerrr get_start_methodszBaseContext.get_start_methodcCstd)Nz+cannot set start method of concrete context)rVrrXZforcerrr 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)r_)rrrrr rbcCdSrYrrarrr rWszBaseContext._check_available)TrY)r)NN)r)NNrNF)+r r r rrrr staticmethodrZcurrent_processZparent_processZactive_childrenrrrr"r%r'r*r,r-r/r2r5r6r7r9r=r?rArDrIrKrNrPrRrr\r^propertyrbsetterrWrrrr rsT                 rc@s(eZdZdZeddZeddZdS)ProcessNcCstj|SrY)_default_contextrri_Popen) process_objrrr rkszProcess._PopencCstjSrY)rjrri _after_forkrrrr rmrczProcess._after_forkr r r _start_methodrfrkrmrrrr ris  ricsFeZdZeZddZd fdd ZdddZdd d Zd d ZZ S)DefaultContextcCs||_d|_dSrY)rj_actual_context)rr8rrr __init__s zDefaultContext.__init__Ncs,|dur|jdur |j|_|jSt|SrY)rqrjsuperr)rrX __class__rr rs   zDefaultContext.get_contextFcCs<|jdur |s td|dur|rd|_dS|||_dS)Nzcontext has already been set)rq RuntimeErrorrr]rrr r^s  zDefaultContext.set_start_methodcCs"|jdur |r dS|j|_|jjSrY)rqrjrZr[rrr r\s zDefaultContext.get_start_methodcCs>tjdkrdgStjdkrddgnddg}tjr|d|S)NrBrHdarwinforkrS)rErFrHAVE_SEND_HANDLEappend)rmethodsrrr get_all_start_methodss  z$DefaultContext.get_all_start_methodsrYre) r r r rirrrr^r\r| __classcell__rrrtr rps  rprBc@eZdZdZeddZdS) ForkProcessrxcCddlm}||SNr)Popen)Z popen_forkrrlrrrr rkr zForkProcess._PopenNr r r rorfrkrrrr rrc@(eZdZdZeddZeddZdS) SpawnProcessrHcCrr)Zpopen_spawn_posixrrrrr rkr SpawnProcess._PopencCrdrYrrrrr rm"SpawnProcess._after_forkNrnrrrr r  rc@r~)ForkServerProcessrScCrr)Zpopen_forkserverrrrrr rk)r zForkServerProcess._PopenNrrrrr r'rrc@eZdZdZeZdS) ForkContextrxN)r r r rZrrirrrr r.rc@r SpawnContextrHNr r r rZrrirrrr r2rrc@seZdZdZeZddZdS)ForkServerContextrScCstjstddS)Nz%forkserver start method not available)rryrVrarrr rW9sz"ForkServerContext._check_availableN)r r r rZrrirWrrrr r6s r)rxrHrSrwrHrxc@r)rrHcCrr)Zpopen_spawn_win32rrrrr rkMr rcCrdrYrrrrr rmRrrNrnrrrr rKrc@rrrrrrr rWrcCst|t_dSrY)rTrjrq)rXrrr _force_start_methoddsrcCs ttddS)Nspawning_popen)rG_tlsrrrr get_spawning_popenms rcCs |t_dSrY)rr)popenrrr set_spawning_popenps rcCs tdurtdt|jdS)NzF%s objects should only be shared between processes through inheritance)rrvtyper )objrrr assert_spawningss r) rrEZ threadingrMrr__all__ ExceptionrrrrobjectrZ BaseProcessrirprFrrrrrrrTrjrZlocalrrrrrrrr sL  ? ,