
    dM-                     0   d dl Z d dlZd dlZddlmZ ddlmZ dZ G d de          Z G d d	e          Z	 G d
 de          Z
 G d de          Z G d de          Z G d dej                  Z G d de          Zej        dk    r G d dej                  Z G d dej                  Z G d dej                  Z G d de          Z G d de          Z G d d e          Z e             e             e            d!Zej        d"k    r eed#                   ZnP eed$                   Zn> G d% dej                  Z G d& de          Zd# e            iZ eed#                   Zd' Z ej                    Zd( Zd) Zd* ZdS )+    N   )process)	reduction c                       e Zd ZdS )ProcessErrorN__name__
__module____qualname__r       )  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/multiprocessing/context.pyr   r              Dr   r   c                       e Zd ZdS )BufferTooShortNr	   r   r   r   r   r      r   r   r   c                       e Zd ZdS )TimeoutErrorNr	   r   r   r   r   r      r   r   r   c                       e Zd ZdS )AuthenticationErrorNr	   r   r   r   r   r      r   r   r   c                      e Zd ZeZeZeZeZ eej	                  Z	 eej
                  Z
 eej                  Zd Zd Zd&dZd Zd Zd'dZd(d
Zd(dZd Zd)dZd*dZd*dZd Z	 	 d+dZd Zd ZdddZdddZd Zd Zd'dZ d Z!d Z"d Z#d'dZ$d,d!Z%d,d"Z&e'd#             Z(e(j)        d$             Z(d% Z*dS )-BaseContextc                 N    t          j                    }|t          d          |S )z(Returns the number of CPUs in the systemNzcannot determine number of cpus)os	cpu_countNotImplementedError)selfnums     r   r   zBaseContext.cpu_count)   s&    lnn;%&GHHHJr   c                 v    ddl m}  ||                                           }|                                 |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   )SyncManagerctx)managersr   get_contextstart)r   r   ms      r   ManagerzBaseContext.Manager1   sF     	*)))))KD,,..///				r   Tc                 $    ddl m}  ||          S )z1Returns two connection object connected by a piper   )Pipe)
connectionr(   )r   duplexr(   s      r   r(   zBaseContext.Pipe<   s"    $$$$$$tF||r   c                 J    ddl m}  ||                                           S )z#Returns a non-recursive lock objectr   )Lockr    )synchronizer,   r#   )r   r,   s     r   r,   zBaseContext.LockA   s3    %%%%%%t((**++++r   c                 J    ddl m}  ||                                           S )zReturns a recursive lock objectr   )RLockr    )r-   r/   r#   )r   r/   s     r   r/   zBaseContext.RLockF   3    &&&&&&u))++,,,,r   Nc                 L    ddl m}  |||                                           S )zReturns a condition objectr   )	Conditionr    )r-   r2   r#   )r   lockr2   s      r   r2   zBaseContext.ConditionK   s5    ******y4#3#3#5#56666r   r   c                 L    ddl m}  |||                                           S )zReturns a semaphore objectr   )	Semaphorer    )r-   r5   r#   )r   valuer5   s      r   r5   zBaseContext.SemaphoreP   s5    ******yD$4$4$6$67777r   c                 L    ddl m}  |||                                           S )z"Returns a bounded semaphore objectr   )BoundedSemaphorer    )r-   r8   r#   )r   r6   r8   s      r   r8   zBaseContext.BoundedSemaphoreU   s6    1111114+;+;+=+=>>>>r   c                 J    ddl m}  ||                                           S )zReturns an event objectr   )Eventr    )r-   r:   r#   )r   r:   s     r   r:   zBaseContext.EventZ   r0   r   c                 P    ddl m}  |||||                                           S )zReturns a barrier objectr   )Barrierr    )r-   r<   r#   )r   partiesactiontimeoutr<   s        r   r<   zBaseContext.Barrier_   s9    ((((((wwT5E5E5G5GHHHHr   r   c                 L    ddl m}  |||                                           S )Returns a queue objectr   )Queuer    )queuesrB   r#   )r   maxsizerB   s      r   rB   zBaseContext.Queued   s5    !!!!!!uW$"2"2"4"45555r   c                 L    ddl m}  |||                                           S )rA   r   )JoinableQueuer    )rC   rF   r#   )r   rD   rF   s      r   rF   zBaseContext.JoinableQueuei   s5    ))))))}W$*:*:*<*<====r   c                 J    ddl m}  ||                                           S )rA   r   )SimpleQueuer    )rC   rH   r#   )r   rH   s     r   rH   zBaseContext.SimpleQueuen   s3    ''''''{t//112222r   r   c                 R    ddl m}  ||||||                                           S )zReturns a process pool objectr   )Pool)context)poolrJ   r#   )r   	processesinitializerinitargsmaxtasksperchildrJ   s         r   rJ   zBaseContext.Pools   sG     	tI{H6F ,,..0 0 0 	0r   c                      ddl m}  ||g|R  S )zReturns a shared objectr   )RawValue)sharedctypesrR   )r   typecode_or_typeargsrR   s       r   rR   zBaseContext.RawValuez   s-    ******x(040000r   c                 &    ddl m}  |||          S )zReturns a shared arrayr   )RawArray)rS   rW   )r   rT   size_or_initializerrW   s       r   rW   zBaseContext.RawArray   s(    ******x(*=>>>r   )r3   c                L    ddl m}  ||g|R ||                                 dS )z$Returns a synchronized shared objectr   )Valuer3   r!   )rS   rZ   r#   )r   rT   r3   rU   rZ   s        r   rZ   zBaseContext.Value   sR    ''''''u% - - -4))++- - - 	-r   c                P    ddl m}  |||||                                           S )z#Returns a synchronized shared arrayr   )Arrayr[   )rS   r]   r#   )r   rT   rX   r3   r]   s        r   r]   zBaseContext.Array   sD    ''''''u%':))++- - - 	-r   c                 z    t           j        dk    r(t          t           dd          rddlm}  |             dS dS dS )zCheck 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spawnra   )r   ra   s     r   ra   zBaseContext.freeze_support   sV     <7""wsHe'D'D"------N #"""r   c                 "    ddl m}  |            S )zZReturn package logger -- if it does not already exist then
        it is created.
        r   )
get_logger)utilrg   )r   rg   s     r   rg   zBaseContext.get_logger   s"     	%$$$$$z||r   c                 $    ddl m}  ||          S )z8Turn on logging and add a handler which prints to stderrr   )log_to_stderr)rh   rj   )r   levelrj   s      r   rj   zBaseContext.log_to_stderr   s$    ''''''}U###r   c                     ddl m} dS )zVInstall support for sending connections and sockets
        between processes
        r   )r)   N) r)   )r   r)   s     r   allow_connection_picklingz%BaseContext.allow_connection_pickling   s     	!       r   c                 (    ddl m}  ||           dS )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)re   rp   )r   
executablerp   s      r   rp   zBaseContext.set_executable   s,    
 	*)))))z"""""r   c                 (    ddl m}  ||           dS )zkSet list of module names to try to load in forkserver process.
        This is really just a hint.
        r   )set_forkserver_preloadN)
forkserverrs   )r   module_namesrs   s      r   rs   z"BaseContext.set_forkserver_preload   s-     	766666|,,,,,r   c                     || S 	 t           |         }n!# t          $ r t          d|z            d w xY w|                                 |S )Nzcannot find context for %r)_concrete_contextsKeyError
ValueError_check_available)r   methodr!   s      r   r#   zBaseContext.get_context   sj    >K	N$V,CC 	N 	N 	N9FBCCM	N
s    2Fc                     | j         S N)_namer   
allow_nones     r   get_start_methodzBaseContext.get_start_method   s
    zr   c                      t          d          )Nz+cannot set start method of concrete context)ry   r   r{   forces      r   set_start_methodzBaseContext.set_start_method   s    FGGGr   c                 D    t                                          d          S )z_Controls how objects will be reduced to a form that can be
        shared with other processes.r   )globalsgetr   s    r   reducerzBaseContext.reducer   s     yy}}[)))r   c                 (    |t                      d<   d S )Nr   )r   )r   r   s     r   r   zBaseContext.reducer   s    !*		+r   c                     d S r}   r   r   s    r   rz   zBaseContext._check_available   s    r   )Tr}   )r   )NN)r   )NNr   NF)+r
   r   r   r   r   r   r   staticmethodr   current_processparent_processactive_childrenr   r&   r(   r,   r/   r2   r5   r8   r:   r<   rB   rF   rH   rJ   rR   rW   rZ   r]   ra   rg   rj   rn   rp   rs   r#   r   r   propertyr   setterrz   r   r   r   r   r      s       L#NL-"l7#:;;O!\'"899N"l7#:;;O  	 	 	   
, , ,
- - -
7 7 7 7
8 8 8 8
? ? ? ?
- - -
I I I I
6 6 6 6
> > > >
3 3 3
 ?A"0 0 0 01 1 1
? ? ?
 37 - - - - - DH - - - - -    $ $ $ $
! ! !# # #- - -      H H H H * * X*
 ^+ + ^+    r   r   c                   >    e Zd ZdZed             Zed             ZdS )ProcessNc                 d    t                                           j                            |           S r}   )_default_contextr#   r   _Popen)process_objs    r   r   zProcess._Popen   s%    ++--5<<[IIIr   c                  b    t                                           j                                        S r}   )r   r#   r   _after_forkr   r   r   r   zProcess._after_fork   s#    ++--5AACCCr   r
   r   r   _start_methodr   r   r   r   r   r   r   r      sU        MJ J \J D D \D D Dr   r   c                   @     e Zd ZeZd Zd fd	Zd	dZd	dZd Z xZ	S )
DefaultContextc                 "    || _         d | _        d S r}   )r   _actual_context)r   rK   s     r   __init__zDefaultContext.__init__   s     '#r   Nc                 ~    || j         | j        | _         | j         S t                                          |          S r}   )r   r   superr#   )r   r{   	__class__s     r   r#   zDefaultContext.get_context   s=    >#+'+'<$''77&&v...r   Fc                     | j         |st          d          ||r	d | _         d S |                     |          | _         d S )Nzcontext has already been set)r   RuntimeErrorr#   r   s      r   r   zDefaultContext.set_start_method   sQ    +E+=>>>>e>#'D F#//77r   c                 H    | j         |rd S | j        | _         | j         j        S r}   )r   r   r~   r   s     r   r   zDefaultContext.get_start_method   s/    ' t#'#8D #))r   c                     t           j        dk    rdgS t           j        dk    rddgnddg}t          j        r|                    d           |S )Nr_   re   darwinforkrt   )rb   rc   r   HAVE_SEND_HANDLEappend)r   methodss     r   get_all_start_methodsz$DefaultContext.get_all_start_methods  sZ    <7""9+.<8+C+Cw''&RYIZG) -|,,,Nr   r}   r   )
r
   r   r   r   r   r#   r   r   r   __classcell__)r   s   @r   r   r      s        G$ $ $/ / / / / /8 8 8 8* * * *      r   r   r_   c                   (    e Zd ZdZed             ZdS )ForkProcessr   c                 $    ddl m}  ||           S Nr   )Popen)
popen_forkr   r   r   s     r   r   zForkProcess._Popen  s$    ))))))5%%%r   Nr
   r   r   r   r   r   r   r   r   r   r     s2        		& 	& 
	& 	& 	&r   r   c                   >    e Zd ZdZed             Zed             ZdS )SpawnProcessre   c                 $    ddl m}  ||           S r   )popen_spawn_posixr   r   s     r   r   zSpawnProcess._Popen  $    0000005%%%r   c                      d S r}   r   r   r   r   r   zSpawnProcess._after_fork"  	     Dr   Nr   r   r   r   r   r     M        		& 	& 
	& 
	 	 
	 	 	r   r   c                   (    e Zd ZdZed             ZdS )ForkServerProcessrt   c                 $    ddl m}  ||           S r   )popen_forkserverr   r   s     r   r   zForkServerProcess._Popen)  s$    //////5%%%r   Nr   r   r   r   r   r   '  s2        $		& 	& 
	& 	& 	&r   r   c                       e Zd ZdZeZdS )ForkContextr   N)r
   r   r   r~   r   r   r   r   r   r   r   .  s        r   r   c                       e Zd ZdZeZdS SpawnContextre   Nr
   r   r   r~   r   r   r   r   r   r   r   2          r   r   c                       e Zd ZdZeZd ZdS )ForkServerContextrt   c                 <    t           j        st          d          d S )Nz%forkserver start method not available)r   r   ry   r   s    r   rz   z"ForkServerContext._check_available9  s)    - J !HIIIJ Jr   N)r
   r   r   r~   r   r   rz   r   r   r   r   r   6  s2        #	J 	J 	J 	J 	Jr   r   )r   re   rt   r   re   r   c                   >    e Zd ZdZed             Zed             ZdS )r   re   c                 $    ddl m}  ||           S r   )popen_spawn_win32r   r   s     r   r   zSpawnProcess._PopenM  r   r   c                      d S r}   r   r   r   r   r   zSpawnProcess._after_forkR  r   r   Nr   r   r   r   r   r   K  r   r   c                       e Zd ZdZeZdS r   r   r   r   r   r   r   W  r   r   c                 4    t           |          t          _        d S r}   )rw   r   r   )r{   s    r   _force_start_methodr   d  s    '9&'A$$$r   c                  .    t          t          dd           S )Nspawning_popen)rd   _tlsr   r   r   get_spawning_popenr   m  s    4)4000r   c                     | t           _        d S r}   )r   r   )popens    r   set_spawning_popenr   p  s    Dr   c                 j    t                      $t          dt          |           j        z            d S )NzF%s objects should only be shared between processes through inheritance)r   r   typer
   )objs    r   assert_spawningr   s  s>    ##%)#YY%78  	 $#r   ) r   rb   	threadingrm   r   r   __all__	Exceptionr   r   r   r   objectr   BaseProcessr   r   rc   r   r   r   r   r   r   rw   r   r   localr   r   r   r   r   r   r   <module>r      s   				 



                
	 	 	 	 	9 	 	 		 	 	 	 	\ 	 	 		 	 	 	 	< 	 	 		 	 	 	 	, 	 	 	x x x x x& x x x|D D D D Dg! D D D% % % % %[ % % %X <7& & & & &g) & & &
 
 
 
 
w* 
 
 
& & & & &G/ & & &    k       {   J J J J JK J J J '')) 
 |x *>*<W*EFF)>*<V*DEE
 
 
 
 
w* 
 
 
    {   
 	 &~&8&ABBB B B y1 1 1         r   