
     @g$                       U d dl m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m	Z	m
Z
 d dlmZmZmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZmZmZ ddl m!Z!m"Z" ddl#m$Z$ dZ% ed          Z& e!d          Z'de(d<    e!d          Z)de(d<    e!d          Z*de(d<   dddd(d"Z+d)d$Z,d*d&Z-e.d'k    r e-             dS dS )+    )annotationsN)deque)module_from_specspec_from_file_location)CallableTypeVarcast   )current_timeget_asynclibget_cancelled_exc_class)BrokenWorkerProcess)open_process)CapacityLimiter)CancelScope
fail_after)ByteReceiveStreamByteSendStreamProcess)RunVarcheckpoint_if_cancelled)BufferedByteReceiveStreami,  T_Retval_process_pool_workerszRunVar[set[Process]]_process_pool_idle_workersz$RunVar[deque[tuple[Process, float]]]_default_process_limiterzRunVar[CapacityLimiter]F)cancellablelimiterfuncCallable[..., T_Retval]argsobjectr   boolr   CapacityLimiter | Nonereturnc          	     	  K   dfd}t                       d{V  t          j        d| |ft          j                  }	 t                                          t                                          }n# t          $ rt t                      t                      }t                                         t                              |           t                                                     Y nw xY w|pt                      4 d{V  |rF|                                \  }j        t          t           j                  t%          t          t&          j                            t+                      }g }	|rr||d	         d
         z
  t,          k     rnW|                                \  }                                                                |	                               |rt7          d          5  |	D ]                                 d{V  	 ddd           n# 1 swxY w Y   n                               |Ft:          j        ddt>          g}
tA          |
tB          j"        tB          j"                   d{V 	 t          t           j                  t%          t          t&          j                            tG          d          5  $                    d           d{V }ddd           n# 1 swxY w Y   |dk    rtK          d|          tM          t:          j'        d         dd          }t          j        dt:          j(        |ft          j                  } ||           d{V  nN# tJ          tS                      f$ r  tT          $ r)}                                 tK          d          |d}~ww xY w+                               t7          |           5  	 t          tX           ||           d{V           v r#|                    t+                      f           cddd           cddd          d{V  S # v r$|                    t+                      f           w w xY w# 1 swxY w Y   	 ddd          d{V  dS # 1 d{V swxY w Y   dS )a  
    Call the given function with the given arguments in a worker process.

    If the ``cancellable`` option is enabled and the task waiting for its completion is cancelled,
    the worker process running it will be abruptly terminated using SIGKILL (or
    ``terminateProcess()`` on Windows).

    :param func: a callable
    :param args: positional arguments for the callable
    :param cancellable: ``True`` to allow cancellation of the operation while it's running
    :param limiter: capacity limiter to use to limit the total amount of processes running
        (if omitted, the default limiter is used)
    :return: an awaitable that yields the return value of the function.

    pickled_cmdbytesr%   r"   c                  K   	 	                     |            d {V                      dd           d {V }|                    d          \  }}|dvrt          d|                              t          |                     d {V }n# t          $ r}
                               	                                  t          d          5  
                                 d {V  d d d            n# 1 swxY w Y   n# t          $ r Y nw xY wt          |t                                r t          |d }~ww xY wt          j        |          }|dk    rt          |t                    sJ ||S )	N   
2       )   RETURN	   EXCEPTION-Worker process returned unexpected response: Tshieldr.   )sendreceive_untilsplitRuntimeErrorreceive_exactlyintBaseExceptiondiscardkillr   acloseProcessLookupError
isinstancer   r   pickleloads)r'   responsestatuslengthpickled_responseexcretvalbufferedprocessstdinworkerss          D/var/www/piapp/venv/lib/python3.11/site-packages/anyio/to_process.pysend_raw_commandz"run_sync.<locals>.send_raw_command4   s     	3**[)))))))))%33E2>>>>>>>>H%^^D11NFF666"PHPP   &.%=%=c&kk%J%JJJJJJJ 	3 	3 	3OOG$$$ --- + +!..*********+ + + + + + + + + + + + + + +%    #68899 3)s2	3 .//\!!fm44444LMs`   BB 
ED?3$D
C>2D
>D	D
D	D
	D?

DD?D(D??ENrun)protocolr   r
   Tr0   z-uz-m)rH   stdout         READY
r/   __main____file__initz*Error during worker process initialization)r'   r(   r%   r"   )-r   r>   dumpsHIGHEST_PROTOCOLr   getr   LookupErrorsetr   r   #setup_process_pool_exit_at_shutdowncurrent_default_process_limiterpop
returncoder	   r   rH   r   r   rN   r   WORKER_MAX_IDLE_TIMEpopleftr:   removeappendr   r;   sys
executable__name__r   
subprocessPIPEr   receiver   getattrmodulespathr   r8   addr   )r   r   r   r!   rK   requestidle_workers
idle_sincenowkilled_processescommandmessagemain_module_pathpickledrD   rF   rG   rH   rI   s                  @@@@rJ   run_syncru      sh     ,        B "
#
########lE4.9PQQQGD'++--15577 D D D%%ww!!'***"&&|444::7CCCCCD <:<< GC GC GC GC GC GC GC GC  <	!"."2"2"4"4GZ!)^W];;4*GN;;  #nn24 " 5\!_Q//2FFF*6*>*>*@*@'GZLLNNNNN7+++$++G444 # 5 !--- / /#3 / /%nn..........// / / / / / / / / / / / / / / NN7###7  <	!: ~tT8<G(zz        G^W];;4*GN;;   ^^ 8 8$,$4$4Q$7$7777777G8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 j((-SSS   $+3;z+BJPT#U#U  ,SX'78#4   '&w//////////')@)B)BC       )@  KK   K000 	C 	CCH,<,<W,E,E&E&E&E&E&E&EFFg%% '',..(ABBB	C 	C 	C 	C 	C 	C 	CEGC GC GC GC GC GC GC GC GC GC GC GC GC GCL g%% '',..(ABBBB &		C 	C 	C 	C 	C 	C 	C 	C 	CEGC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GC GCs   2A; ;A;C98C9C8S
 H7+S7H;	;S>H;	?ASAN.L
NL	NL	A:NS"O$;$OO$$)SR%#Q82'R%S8*R""R%%R)	)S,R)	-S
SSr   c                     	 t                                           S # t          $ rA t          t	          j                    pd          } t                               |            | cY S w xY w)z
    Return the capacity limiter that is used by default to limit the number of worker processes.

    :return: a capacity limiter object

       )r   rW   rX   r   os	cpu_countrY   )r   s    rJ   r[   r[      si    '++---   !",.."5A66 $$W---s    AA&%A&Nonec                    t           j        } t           j        }t          t          j                  t           _        t          t          j        d          t           _        |j                            d           	 d x}}	 t          j	        | j                  ^}}|dk    r%|\  }}	  || }n# t          $ r}|}Y d }~nd }~ww xY w|dk    r|\  t           _        }t           j        d= |rl	 t          d|          }	|	r?|	j        r8t          |	          }
|	j                            |
           |
t           j        d<   n?# t          $ r}|}Y d }~n.d }~ww xY wn%# t"          $ r Y d S t          $ r}|}Y d }~nd }~ww xY w	 |"d}t          j        |t          j                  }n!d	}t          j        |t          j                  }n:# t          $ r-}|}d}t          j        |t          j                  }Y d }~nd }~ww xY w|j                            d
|t)          |          fz             |j                            |           t+          |t,                    r|)NwrQ   TrL   rT   rR   __mp_main__r.   r-   s   %s %d
)rb   rH   rN   openrx   devnullbufferwriter>   loadr8   rj   ri   r   loaderr   exec_moduleEOFErrorrU   rV   lenr=   
SystemExit)rH   rN   rE   	exceptionrq   r!   r   rD   rs   specmainrA   rt   s                rJ   process_workerr      s    IEZFRZ  CIbj#&&CJ
M
###0!!	(#[66NGd %!
d$!T4[FF$ $ $ $ #IIIIII$F""-1**K
+# 
((6}FVWW ;DK ;#3D#9#9D K33D9996:CK
3( ( ( ($'						(1  	 	 	FF 	 	 	IIIIII	2
	A$% ,y&2IJJ" ,vv/FGG 	A 	A 	AI!Fl3(?@@GGGGGG	A
 	J&#g,,)??@@@G$$$ i,, 	Oa0sh    E 'B- -
C7B>>C+AD= =
EEE
E9$	E9-E44E9=AG 
G:#G55G:rR   )
r   r    r!   r"   r   r#   r   r$   r%   r   )r%   r   )r%   rz   )/
__future__r   rx   r>   re   rb   collectionsr   importlib.utilr   r   typingr   r   r	   _core._eventloopr   r   r   _core._exceptionsr   _core._subprocessesr   _core._synchronizationr   _core._tasksr   r   abcr   r   r   lowlevelr   r   streams.bufferedr   r^   r   r   __annotations__r   r   ru   r[   r   rd        rJ   <module>r      s>   " " " " " " " 				      



       D D D D D D D D * * * * * * * * * * Q Q Q Q Q Q Q Q Q Q 2 2 2 2 2 2 - - - - - - 3 3 3 3 3 3 1 1 1 1 1 1 1 1 ; ; ; ; ; ; ; ; ; ; 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7:.4f5L.M.M  M M M MCI6 D D      5;F;U4V4V  V V V V &*	LC LC LC LC LC LC^   9 9 9 9x zN r   