
    RSi                         d Z ddlZddlZddlZddlZddlmZ 	 ddlZn# e$ r dZY nw xY wddl	m
Z
 dad Zd Zd
d	ZdS )zProcess utils.    N)hexlify   )loggerc                      t           dS 	 t          j                    S # t          $ r Y nw xY w	 t          j        d          S # t
          t          f$ r Y nw xY wdS )z1Returns the number of processors on this machine.Nr   SC_NPROCESSORS_CONF)multiprocessing	cpu_countNotImplementedErrorossysconfAttributeError
ValueError     E/home/jrussi/.local/lib/python3.11/site-packages/pyftpdlib/prefork.pyr	   r	      s    q(***   z/000J'   1s    
++A AAc                     	 t          t          t          j        d                    d          } nG# t          $ r: t          t          j                    dz            t          j                    z  } Y nw xY wt          j        |            d S )N   i  )	intr   r   urandomr
   timegetpidrandomseed)r   s    r   _reseed_randomr   &   s    
572:b>>**B// 5 5 549;;%&&45
Ks   /2 AA65A6d   c                    	 t           J | | dk    rt                      } t          j        d|            i 		fd}t	          |           D ]} ||          }||c S d}	r	 t          j                    \  }}n# t          $ r Y 'w xY w|	vr0	                    |          }t          j	        |          r*t          j
        d||t          j        |                     nYt          j        |          dk    r*t          j
        d||t          j        |                     nt          j        d||           |dz  }||k    rt          d	           ||          }||S 	t          j        d           dS )
a  Starts multiple worker processes.

    If *number* is None or <= 0, we detect the number of cores available
    on this machine and fork that number of child processes.
    If *number* is given and > 0, we fork that specific number of
    sub-processes.

    Since we use processes and not threads, there is no shared memory
    between any server code.

    In each child process, *fork_processes* returns its *task id*, a
    number between 0 and *number*.  Processes that exit abnormally
    (due to a signal or non-zero exit status) are restarted with the
    same id (up to *max_restarts* times). In the parent process,
    *fork_processes* returns None if all child processes have exited
    normally, but will otherwise only exit by throwing an exception.
    Nr   zstarting %d pre-fork processesc                 h    t          j                    }|dk    rt                       | a| S | |<   d S )Nr   )r   forkr   _task_id)ipidchildrens     r   start_childz#fork_processes.<locals>.start_childJ   s;    gii!88HHHSM4r   z1child %d (pid %d) killed by signal %d, restartingz3child %d (pid %d) exited with status %d, restartingz!child %d (pid %d) exited normallyr   z"Too many child restarts, giving up)r   r	   r   inforanger   waitInterruptedErrorpopWIFSIGNALEDwarningWTERMSIGWEXITSTATUSRuntimeErrorsysexit)
numbermax_restartsr#   r    idnum_restartsr!   statusnew_idr"   s
            @r   fork_processesr6   2   s   $ ~1
K0&999H
 
 
 
 
 6]]  [^^>III L
 	'))KC 	 	 	H	h\\#>&!! 	NCF##	    ^F##q((NEv&&	    K;REEE,&&CDDDRM=  F HQKKKKKs   &A= =
B
	B
)r   )__doc__r   r   r.   r   binasciir   r   ImportErrorlogr   r   r	   r   r6   r   r   r   <module>r;      s   
   				  



          OOO        	 	 	L L L L L Ls    ))