î ×ê[­)ã@s[ddlZddlZddlZddlmZgZGdd„deƒZGdd„deƒZGdd „d eƒZ Gd d „d eƒZ Gd d „d e ƒZ Gdd„dej ƒZGdd„de ƒZedd„eeƒDƒƒe_ejdkrÌGdd„dej ƒZGdd„dej ƒZGdd„dej ƒZGdd„de ƒZGdd„de ƒZGdd „d e ƒZieƒd!6eƒd"6eƒd#6Zeed!ƒZnOGd$d„dej ƒZGd%d„de ƒZieƒd"6Zeed"ƒZd&d'„ZejƒZd(d)„Zd*d+„Zd,d-„Z dS).éNé)Úprocessc@seZdZdS)Ú ProcessErrorN)Ú__name__Ú __module__Ú __qualname__©rrú-/usr/lib/python3.4/multiprocessing/context.pyr s rc@seZdZdS)ÚBufferTooShortN)rrrrrrr r s r c@seZdZdS)Ú TimeoutErrorN)rrrrrrr r s r c@seZdZdS)ÚAuthenticationErrorN)rrrrrrr r s r c@sÒeZdZeZeZeZeZeej ƒZ eej ƒZ dd„Z dd„Z ddd„Z dd „Zd d „Zd d d„Zddd„Zddd„Zdd„Zd d dd„Zddd„Zddd„Zdd„Zd d fd dd „Zd!d"„Zd#d$„Zd%dd&d'„Zd%dd(d)„Zd*d+„Zd,d-„Zd d.d/„Zd0d1„Z d2d3„Z!d4d5„Z"d d6d7„Z#d8d9d:„Z$d d;d<„Z%d=d>„Z&d S)?Ú BaseContextcCs/tjƒ}|dkr'tdƒ‚n|SdS)z(Returns the number of CPUs in the systemNzcannot determine number of cpus)ÚosÚ cpu_countÚNotImplementedError)ÚselfZnumrrr r's  zBaseContext.cpu_countcCs3ddlm}|d|jƒƒ}|jƒ|S)z½Returns 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)Ú SyncManagerÚctx)ZmanagersrÚ get_contextÚstart)rrÚmrrr ÚManager/s zBaseContext.ManagerTcCsddlm}||ƒS)z1Returns two connection object connected by a piper)ÚPipe)Ú connectionr)rZduplexrrrr r:szBaseContext.PipecCs#ddlm}|d|jƒƒS)z#Returns a non-recursive lock objectr)ÚLockr)Ú synchronizerr)rrrrr r?szBaseContext.LockcCs#ddlm}|d|jƒƒS)zReturns a recursive lock objectr)ÚRLockr)rrr)rrrrr rDszBaseContext.RLockNcCs&ddlm}||d|jƒƒS)zReturns a condition objectr)Ú Conditionr)rrr)rÚlockrrrr rIszBaseContext.ConditionrcCs&ddlm}||d|jƒƒS)zReturns a semaphore objectr)Ú Semaphorer)rrr)rÚvaluerrrr rNszBaseContext.SemaphorecCs&ddlm}||d|jƒƒS)z"Returns a bounded semaphore objectr)ÚBoundedSemaphorer)rr!r)rr r!rrr r!SszBaseContext.BoundedSemaphorecCs#ddlm}|d|jƒƒS)zReturns an event objectr)ÚEventr)rr"r)rr"rrr r"XszBaseContext.EventcCs,ddlm}||||d|jƒƒS)zReturns a barrier objectr)ÚBarrierr)rr#r)rZpartiesÚactionZtimeoutr#rrr r#]szBaseContext.BarrierrcCs&ddlm}||d|jƒƒS)zReturns a queue objectr)ÚQueuer)Úqueuesr%r)rÚmaxsizer%rrr r%bszBaseContext.QueuecCs&ddlm}||d|jƒƒS)zReturns a queue objectr)Ú JoinableQueuer)r&r(r)rr'r(rrr r(gszBaseContext.JoinableQueuecCs#ddlm}|d|jƒƒS)zReturns a queue objectr)Ú SimpleQueuer)r&r)r)rr)rrr r)lszBaseContext.SimpleQueuecCs/ddlm}|||||d|jƒƒS)zReturns a process pool objectr)ÚPoolÚcontext)Zpoolr*r)rZ processesZ initializerZinitargsZmaxtasksperchildr*rrr r*qszBaseContext.PoolcGsddlm}|||ŒS)zReturns a shared objectr)ÚRawValue)Ú sharedctypesr,)rÚtypecode_or_typeÚargsr,rrr r,xszBaseContext.RawValuecCsddlm}|||ƒS)zReturns a shared arrayr)ÚRawArray)r-r0)rr.Úsize_or_initializerr0rrr r0}szBaseContext.RawArrayrcGs/ddlm}||d|d|jƒ|ŒS)z$Returns a synchronized shared objectr)ÚValuerr)r-r2r)rr.rr/r2rrr r2‚szBaseContext.ValuecCs/ddlm}|||d|d|jƒƒS)z#Returns a synchronized shared arrayr)ÚArrayrr)r-r3r)rr.r1rr3rrr r3ˆszBaseContext.ArraycCs?tjdkr;ttddƒr;ddlm}|ƒndS)z‹Check whether this is a fake forked process in a frozen executable. If so then run code specified by commandline and exit. Úwin32ÚfrozenFr)Úfreeze_supportN)ÚsysÚplatformÚgetattrÚspawnr6)rr6rrr r6Žs!zBaseContext.freeze_supportcCsddlm}|ƒS)zZReturn package logger -- if it does not already exist then it is created. r)Ú get_logger)Úutilr;)rr;rrr r;–szBaseContext.get_loggercCsddlm}||ƒS)z8Turn on logging and add a handler which prints to stderrr)Ú log_to_stderr)r<r=)rÚlevelr=rrr r=szBaseContext.log_to_stderrcCsddlm}dS)zVInstall support for sending connections and sockets between processes r)rN)Úr)rrrrr Úallow_connection_pickling¢sz%BaseContext.allow_connection_picklingcCsddlm}||ƒdS)zÌSets 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:rA)rÚ executablerArrr rAªszBaseContext.set_executablecCsddlm}||ƒdS)zkSet list of module names to try to load in forkserver process. This is really just a hint. r)Úset_forkserver_preloadN)Ú forkserverrC)rZ module_namesrCrrr rC²sz"BaseContext.set_forkserver_preloadc CsQ|dkr|Syt|}Wn"tk rBtd|ƒ‚YnX|jƒ|S)Nzcannot find context for %r)Ú_concrete_contextsÚKeyErrorÚ ValueErrorÚ_check_available)rÚmethodrrrr r¹s   zBaseContext.get_contextFcCs|jS)N)Ú_name)rÚ allow_nonerrr Úget_start_methodÃszBaseContext.get_start_methodcCstdƒ‚dS)Nz+cannot set start method of concrete context)rG)rrIrrr Úset_start_methodÆszBaseContext.set_start_methodcCsdS)Nr)rrrr rHÉszBaseContext._check_available)'rrrrr r r Ú staticmethodrZcurrent_processZactive_childrenrrrrrrrr!r"r#r%r(r)r*r,r0r2r3r6r;r=r@rArCrrLrMrHrrrr r sF                r c@s(eZdZdZedd„ƒZdS)ÚProcessNcCstjƒjj|ƒS)N)Ú_default_contextrrOÚ_Popen)Ú process_objrrr rQÒszProcess._Popen)rrrÚ _start_methodrNrQrrrr rOÐs rOcsaeZdZeZdd„Zd‡fdd†Zddd„Zdd d „Zd d „Z‡S) ÚDefaultContextcCs||_d|_dS)N)rPÚ_actual_context)rr+rrr Ú__init__Ùs zDefaultContext.__init__NcsE|dkr1|jdkr*|j|_n|jStƒj|ƒSdS)N)rUrPÚsuperr)rrI)Ú __class__rr rÝs  zDefaultContext.get_contextFcCsZ|jdk r%| r%tdƒ‚n|dkrD|rDd|_dS|j|ƒ|_dS)Nzcontext has already been set)rUÚ RuntimeErrorr)rrIZforcerrr rMås  zDefaultContext.set_start_methodcCs2|jdkr(|rdS|j|_n|jjS)N)rUrPrJ)rrKrrr rLís zDefaultContext.get_start_methodcCsJtjdkrdgSddlm}|jr<dddgSddgSdS)Nr4r:r)Ú reductionÚforkrD)r7r8r?rZÚHAVE_SEND_HANDLE)rrZrrr Úget_all_start_methodsôs   z$DefaultContext.get_all_start_methods) rrrrOrVrrMrLr]rr)rXr rTÖs  rTccs%|]}|ddkr|VqdS)rÚ_Nr)Ú.0Úxrrr ú þsrar4c@s(eZdZdZedd„ƒZdS)Ú ForkProcessr[cCsddlm}||ƒS)Nr)ÚPopen)Z popen_forkrc)rRrcrrr rQszForkProcess._PopenN)rrrrSrNrQrrrr rbs rbc@s(eZdZdZedd„ƒZdS)Ú SpawnProcessr:cCsddlm}||ƒS)Nr)rc)Zpopen_spawn_posixrc)rRrcrrr rQszSpawnProcess._PopenN)rrrrSrNrQrrrr rd s rdc@s(eZdZdZedd„ƒZdS)ÚForkServerProcessrDcCsddlm}||ƒS)Nr)rc)Zpopen_forkserverrc)rRrcrrr rQszForkServerProcess._PopenN)rrrrSrNrQrrrr res rec@seZdZdZeZdS)Ú ForkContextr[N)rrrrJrbrOrrrr rfs rfc@seZdZdZeZdS)Ú SpawnContextr:N)rrrrJrdrOrrrr rgs rgc@s(eZdZdZeZdd„ZdS)ÚForkServerContextrDcCs,ddlm}|js(tdƒ‚ndS)Nr)rZz%forkserver start method not available)r?rZr\rG)rrZrrr rH&s z"ForkServerContext._check_availableN)rrrrJrerOrHrrrr rh#s rhr[r:rDc@s(eZdZdZedd„ƒZdS)rdr:cCsddlm}||ƒS)Nr)rc)Zpopen_spawn_win32rc)rRrcrrr rQ6szSpawnProcess._PopenN)rrrrSrNrQrrrr rd4s c@seZdZdZeZdS)rgr:N)rrrrJrdrOrrrr rg;s cCst|t_dS)N)rErPrU)rIrrr Ú_force_start_methodHsricCsttddƒS)NÚspawning_popen)r9Ú_tlsrrrr Úget_spawning_popenQsrlcCs |t_dS)N)rkrj)Úpopenrrr Úset_spawning_popenTsrncCs/tƒdkr+tdt|ƒjƒ‚ndS)NzF%s objects should only be shared between processes through inheritance)rlrYÚtyper)Úobjrrr Úassert_spawningWsrq)!rr7Z threadingr?rÚ__all__Ú Exceptionrr r r Úobjectr Z BaseProcessrOrTÚlistÚdirr8rbrdrerfrgrhrErPriZlocalrkrlrnrqrrrr ÚsD   ³("