a
    &Rh+                     @   s  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 deZG dd	 d	eZ	G d
d deZ
G dd deZG dd deZG dd dejZG dd deZejdkrRG dd dejZG dd dejZG dd dejZG dd deZG dd deZG dd  d eZe e e d!Zejd"krDeed# Zneed$ Zn8G d%d dejZG d&d deZd#e iZeed# Zd'd( Ze Zd)d* Zd+d, Zd-d. ZdS )/    N   )process)	reduction c                   @   s   e Zd ZdS )ProcessErrorN__name__
__module____qualname__r   r   r   ?/opt/python-3.9.24/usr/lib/python3.9/multiprocessing/context.pyr      s   r   c                   @   s   e Zd ZdS )BufferTooShortNr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )TimeoutErrorNr   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )AuthenticationErrorNr   r   r   r   r   r      s   r   c                   @   sX  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d Zdd ZdCddZdd	 Zd
d ZdDddZdEddZdFddZdd ZdGddZdHddZdIddZdd ZdJd d!Zd"d# Zd$d% Zdd&d'd(Zdd&d)d*Zd+d, Zd-d. ZdKd/d0Z d1d2 Z!d3d4 Z"d5d6 Z#dLd7d8Z$dMd:d;Z%dNd<d=Z&e'd>d? Z(e(j)d@d? Z(dAdB Z*dS )OBaseContextc                 C   s"   t  }|d u rtdn|S d S )Nzcannot determine number of cpus)os	cpu_countNotImplementedError)selfnumr   r   r   r   )   s    
zBaseContext.cpu_countc                 C   s&   ddl m} ||  d}|  |S )Nr   )SyncManagerctx)managersr   get_contextstart)r   r   mr   r   r   Manager1   s    zBaseContext.ManagerTc                 C   s   ddl m} ||S )Nr   )Pipe)
connectionr   )r   duplexr   r   r   r   r   <   s    zBaseContext.Pipec                 C   s   ddl m} ||  dS )Nr   )Lockr   )synchronizer    r   )r   r    r   r   r   r    A   s    zBaseContext.Lockc                 C   s   ddl m} ||  dS )Nr   )RLockr   )r!   r"   r   )r   r"   r   r   r   r"   F   s    zBaseContext.RLockNc                 C   s   ddl m} |||  dS )Nr   )	Conditionr   )r!   r#   r   )r   lockr#   r   r   r   r#   K   s    zBaseContext.Conditionr   c                 C   s   ddl m} |||  dS )Nr   )	Semaphorer   )r!   r%   r   )r   valuer%   r   r   r   r%   P   s    zBaseContext.Semaphorec                 C   s   ddl m} |||  dS )Nr   )BoundedSemaphorer   )r!   r'   r   )r   r&   r'   r   r   r   r'   U   s    zBaseContext.BoundedSemaphorec                 C   s   ddl m} ||  dS )Nr   )Eventr   )r!   r(   r   )r   r(   r   r   r   r(   Z   s    zBaseContext.Eventc                 C   s    ddl m} |||||  dS )Nr   )Barrierr   )r!   r)   r   )r   partiesactiontimeoutr)   r   r   r   r)   _   s    zBaseContext.Barrierr   c                 C   s   ddl m} |||  dS )Nr   )Queuer   )queuesr-   r   )r   maxsizer-   r   r   r   r-   d   s    zBaseContext.Queuec                 C   s   ddl m} |||  dS )Nr   )JoinableQueuer   )r.   r0   r   )r   r/   r0   r   r   r   r0   i   s    zBaseContext.JoinableQueuec                 C   s   ddl m} ||  dS )Nr   )SimpleQueuer   )r.   r1   r   )r   r1   r   r   r   r1   n   s    zBaseContext.SimpleQueuer   c                 C   s"   ddl m} ||||||  dS )Nr   )Pool)context)poolr2   r   )r   	processesinitializerinitargsmaxtasksperchildr2   r   r   r   r2   s   s    
zBaseContext.Poolc                 G   s   ddl m} ||g|R  S )Nr   )RawValue)sharedctypesr9   )r   typecode_or_typeargsr9   r   r   r   r9   z   s    zBaseContext.RawValuec                 C   s   ddl m} |||S )Nr   )RawArray)r:   r=   )r   r;   size_or_initializerr=   r   r   r   r=      s    zBaseContext.RawArray)r$   c                G   s(   ddl m} ||g|R ||  dS )Nr   )Valuer$   r   )r:   r?   r   )r   r;   r$   r<   r?   r   r   r   r?      s    zBaseContext.Valuec                C   s    ddl m} |||||  dS )Nr   )Arrayr@   )r:   rA   r   )r   r;   r>   r$   rA   r   r   r   rA      s    zBaseContext.Arrayc                 C   s,   t jdkr(tt ddr(ddlm} |  d S )Nwin32frozenFr   )freeze_support)sysplatformgetattrspawnrD   )r   rD   r   r   r   rD      s    zBaseContext.freeze_supportc                 C   s   ddl m} | S )Nr   )
get_logger)utilrI   )r   rI   r   r   r   rI      s    zBaseContext.get_loggerc                 C   s   ddl m} ||S )Nr   )log_to_stderr)rJ   rK   )r   levelrK   r   r   r   rK      s    zBaseContext.log_to_stderrc                 C   s   ddl m} d S )Nr   )r   ) r   )r   r   r   r   r   allow_connection_pickling   s    z%BaseContext.allow_connection_picklingc                 C   s   ddl m} || d S )Nr   )set_executable)rH   rO   )r   
executablerO   r   r   r   rO      s    zBaseContext.set_executablec                 C   s   ddl m} || d S )Nr   )set_forkserver_preload)
forkserverrQ   )r   module_namesrQ   r   r   r   rQ      s    z"BaseContext.set_forkserver_preloadc                 C   sF   |d u r| S zt | }W n  ty8   td| d Y n0 |  |S )Nzcannot find context for %r)_concrete_contextsKeyError
ValueError_check_available)r   methodr   r   r   r   r      s    zBaseContext.get_contextFc                 C   s   | j S N)_namer   
allow_noner   r   r   get_start_method   s    zBaseContext.get_start_methodc                 C   s   t dd S )Nz+cannot set start method of concrete context)rV   r   rX   forcer   r   r   set_start_method   s    zBaseContext.set_start_methodc                 C   s   t  dS Nr   )globalsgetr   r   r   r   reducer   s    zBaseContext.reducerc                 C   s   |t  d< d S ra   )rb   )r   r   r   r   r   re      s    c                 C   s   d S rY   r   rd   r   r   r   rW      s    zBaseContext._check_available)T)N)r   )r   )NN)r   )r   )NNr   N)N)N)F)F)+r   r	   r
   r   r   r   r   staticmethodr   current_processparent_processactive_childrenr   r   r   r    r"   r#   r%   r'   r(   r)   r-   r0   r1   r2   r9   r=   r?   rA   rD   rI   rK   rN   rO   rQ   r   r]   r`   propertyre   setterrW   r   r   r   r   r      sR   









  







r   c                   @   s   e Zd ZdZedd ZdS )ProcessNc                 C   s   t  j| S rY   )_default_contextr   rl   _Popen)process_objr   r   r   rn      s    zProcess._Popenr   r	   r
   _start_methodrf   rn   r   r   r   r   rl      s   rl   c                       sF   e Zd ZeZdd Zd fdd	ZdddZdd	d
Zdd Z  Z	S )DefaultContextc                 C   s   || _ d | _d S rY   )rm   _actual_context)r   r3   r   r   r   __init__   s    zDefaultContext.__init__Nc                    s0   |d u r | j d u r| j| _ | j S t |S d S rY   )rs   rm   superr   )r   rX   	__class__r   r   r      s
    
zDefaultContext.get_contextFc                 C   s<   | j d ur|std|d u r,|r,d | _ d S | || _ d S )Nzcontext has already been set)rs   RuntimeErrorr   r^   r   r   r   r`      s    zDefaultContext.set_start_methodc                 C   s"   | j d u r|rd S | j| _ | j jS rY   )rs   rm   rZ   r[   r   r   r   r]      s
    
zDefaultContext.get_start_methodc                 C   sB   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 d S )NrB   rH   darwinforkrR   )rE   rF   r   HAVE_SEND_HANDLEappend)r   methodsr   r   r   get_all_start_methods   s    

z$DefaultContext.get_all_start_methods)N)F)F)
r   r	   r
   rl   rt   r   r`   r]   r~   __classcell__r   r   rv   r   rr      s   

rr   rB   c                   @   s   e Zd ZdZedd ZdS )ForkProcessrz   c                 C   s   ddl m} || S Nr   )Popen)
popen_forkr   ro   r   r   r   r   rn     s    zForkProcess._PopenNrp   r   r   r   r   r     s   r   c                   @   s   e Zd ZdZedd ZdS )SpawnProcessrH   c                 C   s   ddl m} || S r   )popen_spawn_posixr   r   r   r   r   rn     s    SpawnProcess._PopenNrp   r   r   r   r   r     s   r   c                   @   s   e Zd ZdZedd ZdS )ForkServerProcessrR   c                 C   s   ddl m} || S r   )popen_forkserverr   r   r   r   r   rn      s    zForkServerProcess._PopenNrp   r   r   r   r   r     s   r   c                   @   s   e Zd ZdZeZdS )ForkContextrz   N)r   r	   r
   rZ   r   rl   r   r   r   r   r   %  s   r   c                   @   s   e Zd ZdZeZdS SpawnContextrH   Nr   r	   r
   rZ   r   rl   r   r   r   r   r   )  s   r   c                   @   s   e Zd ZdZeZdd ZdS )ForkServerContextrR   c                 C   s   t jstdd S )Nz%forkserver start method not available)r   r{   rV   rd   r   r   r   rW   0  s    z"ForkServerContext._check_availableN)r   r	   r
   rZ   r   rl   rW   r   r   r   r   r   -  s   r   )rz   rH   rR   ry   rH   rz   c                   @   s   e Zd ZdZedd ZdS )r   rH   c                 C   s   ddl m} || S r   )Zpopen_spawn_win32r   r   r   r   r   rn   D  s    r   Nrp   r   r   r   r   r   B  s   c                   @   s   e Zd ZdZeZdS r   r   r   r   r   r   r   I  s   c                 C   s   t |  t_d S rY   )rT   rm   rs   )rX   r   r   r   _force_start_methodV  s    r   c                   C   s   t tdd S )Nspawning_popen)rG   _tlsr   r   r   r   get_spawning_popen_  s    r   c                 C   s
   | t _d S rY   )r   r   )popenr   r   r   set_spawning_popenb  s    r   c                 C   s    t  d u rtdt| j d S )NzF%s objects should only be shared between processes through inheritance)r   rx   typer   )objr   r   r   assert_spawninge  s    
r   ) r   rE   	threadingrM   r   r   __all__	Exceptionr   r   r   r   objectr   BaseProcessrl   rr   rF   r   r   r   r   r   r   rT   rm   r   localr   r   r   r   r   r   r   r   <module>   sJ    ?,