
    ⾙hb3                        d dl Z d dlZd dlZd dlZddlmZ g ZdZddlm	Z	m
Z
mZmZmZmZmZ  G d d      Z G d d	ej"                        Z G d
 de      Z ed  ee      D              e_        ej,                  dk7  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ed         Zn4 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$y)#    N   )processzIforce_execv is not supported as the billiard C extension is not installed)ProcessErrorBufferTooShortTimeoutErrorAuthenticationErrorTimeLimitExceededSoftTimeLimitExceededWorkerLostErrorc                   b   e Zd ZeZeZeZeZeZeZe	Z	 e
ej                        Z e
ej                        Z eed      rd Zn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 Z d Z!d Z"d Z#d#dZ$d Z%d Z&d Z'd#dZ(d(dZ)d#dZ*d Z+d  Z,d! Z-y))BaseContext	cpu_countc                 H    t        j                         }|t        d      |S )z(Returns the number of CPUs in the systemcannot determine number of cpus)osr   NotImplementedError)selfnums     L/var/www/Befach/backend/env/lib/python3.12/site-packages/billiard/context.pyr   zBaseContext.cpu_count2   s#    ,,.C{)*KLL
    c                 D   t         j                  dk(  r	 t        t        j                  d         }ndt         j                  v st         j                  dk(  rSd}t         j                  dk(  rd|z   }	 t        j                  |      5 }t        |j                               }d d d        n	 t        j                  d      }d	k\  r|S t        d
      # t
        t        f$ r d}Y %w xY w# 1 sw Y   IxY w# t
        $ r d}Y Bw xY w# t
        t        t        f$ r d}Y ^w xY w)Nwin32NUMBER_OF_PROCESSORSr   bsddarwinz/sbin/sysctl -n hw.ncpuz/usrSC_NPROCESSORS_ONLNr   r   )sysplatformintr   environ
ValueErrorKeyErrorpopenreadsysconfOSErrorAttributeErrorr   )r   r   commps       r   r   zBaseContext.cpu_count:   s	   ||w&bjj)?@AC #,,&#,,(*B0<<8+!D=D$ ,1!!&&(m,
**%:;C ax
)*KLL) #H- C, ,! C
 #G^< CsM   C 2C5 C)!C5 +D C&%C&)C2.C5 5DDDDc                 `    ddl m}  || j                               }|j                          |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.ManagerT   s(     	*D,,./		r   c                 "    ddl m}  ||||      S )z1Returns two connection object connected by a piper   )Pipe)
connectionr4   )r   duplex	rnonblock	wnonblockr4   s        r   r4   zBaseContext.Pipe_   s    $FIy11r   c                 <    ddl m}  || j                               S )z#Returns a non-recursive lock objectr   )Lockr,   )synchronizer:   r/   )r   r:   s     r   r:   zBaseContext.Lockd   s    %((*++r   c                 <    ddl m}  || j                               S )zReturns a recursive lock objectr   )RLockr,   )r;   r=   r/   )r   r=   s     r   r=   zBaseContext.RLocki       &))+,,r   Nc                 >    ddl m}  ||| j                               S )zReturns a condition objectr   )	Conditionr,   )r;   r@   r/   )r   lockr@   s      r   r@   zBaseContext.Conditionn   s    *4#3#3#566r   c                 >    ddl m}  ||| j                               S )zReturns a semaphore objectr   )	Semaphorer,   )r;   rC   r/   )r   valuerC   s      r   rC   zBaseContext.Semaphores   s    *D$4$4$677r   c                 >    ddl m}  ||| j                               S )z"Returns a bounded semaphore objectr   )BoundedSemaphorer,   )r;   rF   r/   )r   rD   rF   s      r   rF   zBaseContext.BoundedSemaphorex   s    14+;+;+=>>r   c                 <    ddl m}  || j                               S )zReturns an event objectr   )Eventr,   )r;   rH   r/   )r   rH   s     r   rH   zBaseContext.Event}   r>   r   c                 B    ddl m}  ||||| j                               S )zReturns a barrier objectr   )Barrierr,   )r;   rJ   r/   )r   partiesactiontimeoutrJ   s        r   rJ   zBaseContext.Barrier   s    (wT5E5E5GHHr   c                 >    ddl m}  ||| j                               S )Returns a queue objectr   )Queuer,   )queuesrP   r/   )r   maxsizerP   s      r   rP   zBaseContext.Queue   s    !W$"2"2"455r   c                 >    ddl m}  ||| j                               S )rO   r   )JoinableQueuer,   )rQ   rT   r/   )r   rR   rT   s      r   rT   zBaseContext.JoinableQueue   s    )W$*:*:*<==r   c                 <    ddl m}  || j                               S )rO   r   )SimpleQueuer,   )rQ   rV   r/   )r   rV   s     r   rV   zBaseContext.SimpleQueue   s    't//122r   c                 ^    ddl m}  ||||||||||	|
|||||||| j                               S )zReturns a process pool objectr   )Pool)context)poolrX   r/   )r   	processesinitializerinitargsmaxtasksperchildrM   soft_timeoutlost_worker_timeoutmax_restartsmax_restart_freqon_process_upon_process_downon_timeout_seton_timeout_cancelthreads	semaphoreputlocksallow_restartrX   s                      r   rX   zBaseContext.Pool   sJ     	I{H6F\+> "2M#^5FY- ,,.0 	0r   c                      ddl m}  ||g| S )zReturns a shared objectr   )RawValue)sharedctypesrl   )r   typecode_or_typeargsrl   s       r   rl   zBaseContext.RawValue   s    *(0400r   c                      ddl m}  |||      S )zReturns a shared arrayr   )RawArray)rm   rq   )r   rn   size_or_initializerrq   s       r   rq   zBaseContext.RawArray   s    *(*=>>r   c                 h    ddl m} |j                  dd      } ||g||| j                         dS )z$Returns a synchronized shared objectr   )ValuerA   TrA   r-   )rm   rt   getr/   )r   rn   ro   kwargsrt   rA   s         r   rt   zBaseContext.Value   s?    'zz&$'% - -4))+- 	-r   c                 f    ddl m} |j                  dd      } ||||| j                               S )z#Returns a synchronized shared arrayr   )ArrayrA   Tru   )rm   ry   rv   r/   )r   rn   rr   ro   rw   ry   rA   s          r   ry   zBaseContext.Array   s6    'zz&$'%':))+- 	-r   c                 j    t         j                  dk(  r t        t         dd      rddlm}  |        yyy)zCheck whether this is a fake forked process in a frozen executable.
        If so then run code specified by commandline and exit.
        r   frozenFr   )freeze_supportN)r   r   getattrspawnr|   )r   r|   s     r   r|   zBaseContext.freeze_support   s-     <<7"wsHe'D- (E"r   c                     ddl m}  |       S )zZReturn package logger -- if it does not already exist then
        it is created.
        r   )
get_logger)utilr   )r   r   s     r   r   zBaseContext.get_logger   s     	%|r   c                     ddl m}  ||      S )z8Turn on logging and add a handler which prints to stderrr   )log_to_stderr)r   r   )r   levelr   s      r   r   zBaseContext.log_to_stderr   s    'U##r   c                     ddl m} y)zVInstall support for sending connections and sockets
        between processes
        r   )r5   N) r5   )r   r5   s     r   allow_connection_picklingz%BaseContext.allow_connection_pickling   s     	!r   c                      ddl m}  ||       y)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)r~   r   )r   
executabler   s      r   r   zBaseContext.set_executable   s    
 	*z"r   c                      ddl m}  ||       y)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   s      r   r   z"BaseContext.set_forkserver_preload   s     	7|,r   c                 x    || S 	 t         |   }|j                          |S # t        $ r t        d|z        w xY w)Nzcannot find context for %r)_concrete_contextsr"   r!   _check_available)r   methodr-   s      r   r/   zBaseContext.get_context   sS    >K	D$V,C 	
  	D9FBCC	Ds   	! 9c                     | j                   S N)_namer   
allow_nones     r   get_start_methodzBaseContext.get_start_method   s    zzr   c                     t        d      )Nz+cannot set start method of concrete context)r!   )r   r   s     r   set_start_methodzBaseContext.set_start_method   s    FGGr   c                 0    | j                         xs ddk(  S )Nfork)r   r   s    r   forking_is_enabledzBaseContext.forking_is_enabled   s    %%'16f<<r   c                     |s?ddl m} |r| j                  dd       y t        j                  t        t                     y y )Nr   )supports_execr~   T)force)_extr   r   warningswarnRuntimeWarning
W_NO_EXECV)r   rD   r   s      r   forking_enablezBaseContext.forking_enable   s4    +%%gT%:nZ89 r   c                      y r    r   s    r   r   zBaseContext._check_available  s    r   )TFFr   )r   )NN)r   )NNr   NNNNNr   NNNNTNFFF).__name__
__module____qualname__r   r   r   r   r	   r
   r   staticmethodr   current_processactive_childrenhasattrr   r   r2   r4   r:   r=   r@   rC   rF   rH   rJ   rP   rT   rV   rX   rl   rq   rt   ry   r|   r   r   r   r   r   r/   r   r   r   r   r   r   r   r   r   r   $   s   L#NL-)1%O"7#:#:;O"7#:#:;Or;		M4	2
,
-
7
8
?
-
I
6
>
3
 ?A?C48EIBF;@01
?
--$
!#-H=:r   r   c                        e Zd ZdZed        Zy)ProcessNc                 \    t         j                         j                  j                  |       S r   )_default_contextr/   r   _Popen)process_objs    r   r   zProcess._Popen  s"    ++-55<<[IIr   r   r   r   _start_methodr   r   r   r   r   r   r     s    MJ J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 | _        y r   )r   _actual_context)r   rY   s     r   __init__zDefaultContext.__init__  s     '#r   c                     |)| j                   | j                  | _         | j                   S t        t        |   |      S r   )r   r   superr   r/   )r   r   	__class__s     r   r/   zDefaultContext.get_context  s@    >##+'+'<'<$''':6BBr   c                 z    | j                   |st        d      |
|rd | _         y | j                  |      | _         y )Nzcontext has already been set)r   RuntimeErrorr/   )r   r   r   s      r   r   zDefaultContext.set_start_method$  sA    +E=>>>e#'D #//7r   c                 n    | j                   |ry | j                  | _         | j                   j                  S r   )r   r   r   r   s     r   r   zDefaultContext.get_start_method,  s4    '#'#8#8D ##)))r   c                 b    t         j                  dk(  rdgS ddlm} |j                  rg dS ddgS )Nr   r~   r   	reductionr   r~   r   r   )r   r   r   r   HAVE_SEND_HANDLEr   r   s     r   get_all_start_methodsz$DefaultContext.get_all_start_methods3  s3    <<7"9#))66((r   r   r   )
r   r   r   r   r   r/   r   r   r   __classcell__)r   s   @r   r   r     s"    G$C8*)r   r   c              #   2   K   | ]  }|d    dk7  s|  yw)r   _Nr   ).0xs     r   	<genexpr>r   =  s     LA!aLs   r   c                        e Zd ZdZed        Zy)ForkProcessr   c                     ddl m}  ||       S Nr   )Popen)
popen_forkr   r   r   s     r   r   zForkProcess._PopenH  s    )%%r   Nr   r   r   r   r   r   E  s    		& 
	&r   r   c                        e Zd ZdZed        Zy)SpawnProcessr~   c                     ddl m}  ||       S r   )popen_spawn_posixr   r   s     r   r   zSpawnProcess._PopenP      0%%r   Nr   r   r   r   r   r   M      		& 
	&r   r   c                        e Zd ZdZed        Zy)ForkServerProcessr   c                     ddl m}  ||       S r   )popen_forkserverr   r   s     r   r   zForkServerProcess._PopenX  s    /%%r   Nr   r   r   r   r   r   U  s    $		& 
	&r   r   c                       e Zd ZdZeZy)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ySpawnContextr~   Nr   r   r   r   r   r   r   r   r   r   r   a      r   r   c                       e Zd ZdZeZd Zy)ForkServerContextr   c                 >    ddl m} |j                  st        d      y )Nr   r   z%forkserver start method not available)r   r   r   r!   r   s     r   r   z"ForkServerContext._check_availablei  s    #-- !HII .r   N)r   r   r   r   r   r   r   r   r   r   r   r   e  s    #	Jr   r   r   r   c                        e Zd ZdZed        Zy)r   r~   c                     ddl m}  ||       S r   )popen_spawn_win32r   r   s     r   r   zSpawnProcess._Popenz  r   r   Nr   r   r   r   r   r   w  r   r   c                       e Zd ZdZeZyr   r   r   r   r   r   r     r   r   r~   c                 (    t         |    t        _        y r   )r   r   r   )r   s    r   _force_start_methodr     s    '9&'A$r   c                  $    t        t        dd       S )Nspawning_popen)r}   _tlsr   r   r   get_spawning_popenr     s    4)400r   c                     | t         _        y r   )r   r   )r#   s    r   set_spawning_popenr     s
    Dr   c                 Z    t               !t        dt        |       j                  z        y )NzF%s objects should only be shared between processes through inheritance)r   r   typer   )objs    r   assert_spawningr     s4    ##%)#Y%7%78
 	
 $r   )%r   r   	threadingr   r   r   __all__r   
exceptionsr   r   r   r   r	   r
   r   r   BaseProcessr   r   listdirr   r   r   r   r   r   r   r   r   r   localr   r   r   r   r   r   r   <module>r     su   	 
   

  b bRJg!! J&)[ &)P L^)<LL  <<7&g)) &&w** &&G// &k { JK J ')
 &&8&@A&w** &{ 
 	 &&8&ABB y1 
r   