3 \*@sddlZddlZddlZddlmZddlmZgZGdddeZGdddeZ Gd d d eZ Gd d d eZ Gd dde Z GdddejZGddde ZeddeeDe_ejdkrPGdddejZGdddejZGdddejZGddde ZGddde ZGd d!d!e Zeeed"Zeed#Zn8Gd$ddejZGd%dde Zd&eiZeed&Zd'd(ZejZd)d*Zd+d,Z d-d.Z!dS)/N)process) reductionc@s eZdZdS) ProcessErrorN)__name__ __module__ __qualname__r r //usr/lib64/python3.6/multiprocessing/context.pyrsrc@s eZdZdS)BufferTooShortN)rrrr r r r r sr c@s eZdZdS) TimeoutErrorN)rrrr r r r r sr c@s eZdZdS)AuthenticationErrorN)rrrr r r r r sr c@sVeZdZeZeZeZeZeej Z eej Z ddZ ddZ dBddZ dd Zd d ZdCd dZdDddZdEddZddZdFddZdGddZdHddZddZd d fd fdd Zd!d"Zd#d$Zdd%d&d'Zdd%d(d)Zd*d+Zd,d-ZdId.d/Zd0d1Z d2d3Z!d4d5Z"dJd6d7Z#dKd9d:Z$dLd;d<Z%e&d=d>Z'e'j(d?d>Z'd@dAZ)d S)M BaseContextcCs"tj}|dkrtdn|SdS)Nzcannot determine number of cpus)os cpu_countNotImplementedError)selfZnumr r r r(s zBaseContext.cpu_countcCs&ddlm}||jd}|j|S)Nr) SyncManager)ctx)Zmanagersr get_contextstart)rrmr r r Manager0s zBaseContext.ManagerTcCsddlm}||S)Nr)Pipe) connectionr)rZduplexrr r r r;s zBaseContext.PipecCsddlm}||jdS)Nr)Lock)r) synchronizerr)rrr r r r@s zBaseContext.LockcCsddlm}||jdS)Nr)RLock)r)rrr)rrr r r rEs zBaseContext.RLockNcCsddlm}|||jdS)Nr) Condition)r)rrr)rlockrr r r rJs zBaseContext.ConditionrcCsddlm}|||jdS)Nr) Semaphore)r)rr r)rvaluer r r r r Os zBaseContext.SemaphorecCsddlm}|||jdS)Nr)BoundedSemaphore)r)rr"r)rr!r"r r r r"Ts zBaseContext.BoundedSemaphorecCsddlm}||jdS)Nr)Event)r)rr#r)rr#r r r r#Ys zBaseContext.EventcCs ddlm}|||||jdS)Nr)Barrier)r)rr$r)rZpartiesactionZtimeoutr$r r r r$^s zBaseContext.BarrierrcCsddlm}|||jdS)Nr)Queue)r)queuesr&r)rmaxsizer&r r r r&cs zBaseContext.QueuecCsddlm}|||jdS)Nr) JoinableQueue)r)r'r)r)rr(r)r r r r)hs zBaseContext.JoinableQueuecCsddlm}||jdS)Nr) SimpleQueue)r)r'r*r)rr*r r r r*ms zBaseContext.SimpleQueuecCs"ddlm}||||||jdS)Nr)Pool)context)Zpoolr+r)rZ processesZ initializerZinitargsZmaxtasksperchildr+r r r r+rs  zBaseContext.PoolcGsddlm}||f|S)Nr)RawValue) sharedctypesr-)rtypecode_or_typeargsr-r r r r-ys zBaseContext.RawValuecCsddlm}|||S)Nr)RawArray)r.r1)rr/size_or_initializerr1r r r r1~s zBaseContext.RawArray)rcGs&ddlm}||f|||jdS)Nr)Value)rr)r.r3r)rr/rr0r3r r r r3s  zBaseContext.ValuecCs ddlm}|||||jdS)Nr)Array)rr)r.r4r)rr/r2rr4r r r r4s zBaseContext.ArraycCs,tjdkr(ttddr(ddlm}|dS)Nwin32frozenFr)freeze_support)sysplatformgetattrspawnr7)rr7r r r r7s zBaseContext.freeze_supportcCsddlm}|S)Nr) get_logger)utilr<)rr<r r r r<s zBaseContext.get_loggercCsddlm}||S)Nr) log_to_stderr)r=r>)rlevelr>r r r r>s zBaseContext.log_to_stderrcCsddlm}dS)Nr)r)r)rrr r r allow_connection_picklingsz%BaseContext.allow_connection_picklingcCsddlm}||dS)Nr)set_executable)r;rB)r executablerBr r r rBs zBaseContext.set_executablecCsddlm}||dS)Nr)set_forkserver_preload) forkserverrD)rZ module_namesrDr r r rDs z"BaseContext.set_forkserver_preloadc CsF|dkr |Sy t|}Wn tk r8td|YnX|j|S)Nzcannot find context for %r)_concrete_contextsKeyError ValueError_check_available)rmethodrr r r rs zBaseContext.get_contextFcCs|jS)N)_name)r allow_noner r r get_start_methodszBaseContext.get_start_methodcCs tddS)Nz+cannot set start method of concrete context)rH)rrJforcer r r set_start_methodszBaseContext.set_start_methodcCs tjdS)Nr)globalsget)rr r r reducerszBaseContext.reducercCs|td<dS)Nr)rP)rrr r r rRscCsdS)Nr )rr r r rIszBaseContext._check_available)T)N)r)r)NN)r)r)N)N)F)F)*rrrrr r r staticmethodrZcurrent_processZactive_childrenrrrrrrr r"r#r$r&r)r*r+r-r1r3r4r7r<r>rArBrDrrMrOpropertyrRsetterrIr r r r rsJ              rc@seZdZdZeddZdS)ProcessNcCstjjj|S)N)_default_contextrrV_Popen) process_objr r r rXszProcess._Popen)rrr _start_methodrSrXr r r r rVsrVcsFeZdZeZddZd fdd ZdddZdd d Zd d ZZ S)DefaultContextcCs||_d|_dS)N)rW_actual_context)rr,r r r __init__szDefaultContext.__init__Ncs0|dkr |jdkr|j|_|jStj|SdS)N)r\rWsuperr)rrJ) __class__r r rs  zDefaultContext.get_contextFcCs>|jdk r| rtd|dkr.|r.d|_dS|j||_dS)Nzcontext has already been set)r\ RuntimeErrorr)rrJrNr r r rOs  zDefaultContext.set_start_methodcCs"|jdkr|rdS|j|_|jjS)N)r\rWrK)rrLr r r rMs  zDefaultContext.get_start_methodcCs,tjdkrdgStjr dddgSddgSdS)Nr5r;forkrE)r8r9rHAVE_SEND_HANDLE)rr r r get_all_start_methodss   z$DefaultContext.get_all_start_methods)N)F)F) rrrrVr]rrOrMrc __classcell__r r )r_r r[s   r[ccs|]}|ddkr|VqdS)r_Nr ).0xr r r srhr5c@seZdZdZeddZdS) ForkProcessracCsddlm}||S)Nr)Popen)Z popen_forkrj)rYrjr r r rXs zForkProcess._PopenN)rrrrZrSrXr r r r risric@seZdZdZeddZdS) SpawnProcessr;cCsddlm}||S)Nr)rj)Zpopen_spawn_posixrj)rYrjr r r rXs zSpawnProcess._PopenN)rrrrZrSrXr r r r rksrkc@seZdZdZeddZdS)ForkServerProcessrEcCsddlm}||S)Nr)rj)Zpopen_forkserverrj)rYrjr r r rX s zForkServerProcess._PopenN)rrrrZrSrXr r r r rlsrlc@seZdZdZeZdS) ForkContextraN)rrrrKrirVr r r r rm%srmc@seZdZdZeZdS) SpawnContextr;N)rrrrKrkrVr r r r rn)srnc@seZdZdZeZddZdS)ForkServerContextrEcCstjstddS)Nz%forkserver start method not available)rrbrH)rr r r rI0sz"ForkServerContext._check_availableN)rrrrKrlrVrIr r r r ro-sro)rar;rErac@seZdZdZeddZdS)rkr;cCsddlm}||S)Nr)rj)Zpopen_spawn_win32rj)rYrjr r r rX?s zSpawnProcess._PopenN)rrrrZrSrXr r r r rk=sc@seZdZdZeZdS)rnr;N)rrrrKrkrVr r r r rnDsr;cCst|t_dS)N)rFrWr\)rJr r r _force_start_methodQsrpcCs ttddS)Nspawning_popen)r:_tlsr r r r get_spawning_popenZsrscCs |t_dS)N)rrrq)popenr r r set_spawning_popen]srucCs tdkrtdt|jdS)NzF%s objects should only be shared between processes through inheritance)rsr`typer)objr r r assert_spawning`s rx)"rr8Z threadingr@rr__all__ Exceptionrr r r objectrZ BaseProcessrVr[listdirr9rirkrlrmrnrorFrWrpZlocalrrrsrurxr r r r sD  >'