HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib64/python3.10/site-packages/anyio/__pycache__/to_interpreter.cpython-310.pyc
o

�hJ�@s�UddlmZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZddl
mZmZddlmZdd	lmZdd
lmZejdkrQddl	mZmZnddlmZmZejd
krsddlmZmZd;dd�ZGdd�d�ZnDejdkr�ddlZddl Z dZ!de"d<dZ#de"d<dZ$de"d<e$e!fZ%de"d<e#e!fZ&de"d<e'dd d!�Z(Gd"d�d�ZnGd#d�d�Zd$Z)de"d%<d&Z*ed'�Z+ed(�Z,eeed)�Z-eed*�Z.d<d/d0�Z/dd1�d=d6d7�Z0d>d9d:�Z1dS)?�)�annotationsN)�deque)�Callable)�Any�Final�TypeVar�)�current_time�	to_thread)�BrokenWorkerInterpreter)�CapacityLimiter)�RunVar)��)�TypeVarTuple�Unpack)r�)�ExecutionFailed�create�func�Callable[..., Any]�args�tuple[Any, ...]c
Cs@z	||�}W|dfSty}z
|dfWYd}~Sd}~ww)NTF)�
BaseException)rr�retval�exc�r�G/usr/local/CyberCP/lib/python3.10/site-packages/anyio/to_interpreter.py�_interp_calls
���rc@�8eZdZUdZded<ddd�Zddd	�Zddd�ZdS)�Workerr�float�	last_used�return�NonecCst�|_dS�N)r�_interpreter��selfrrr�__init__"s�Worker.__init__cCs|j��dSr%)r&�closer'rrr�destroy%s�Worker.destroyr�Callable[..., T_Retval]rr�T_Retvalc
CsJz|j�t||�\}}Wnty}zt|j�|�d}~ww|r#|�|Sr%)r&�callrrr�excinfo)r(rr�res�is_exceptionrrrrr0(s���Worker.callN�r#r$�rr.rrr#r/��__name__�
__module__�__qualname__r"�__annotations__r)r,r0rrrrr s



r )r�
�r�UNBOUND�
FMT_UNPICKLED�FMT_PICKLED�QUEUE_PICKLE_ARGS�QUEUE_UNPICKLE_ARGSa_
import _interpqueues
from _interpreters import NotShareableError
from pickle import loads, dumps, HIGHEST_PROTOCOL

QUEUE_PICKLE_ARGS = (1, 2)
QUEUE_UNPICKLE_ARGS = (0, 2)

item = _interpqueues.get(queue_id)[0]
try:
    func, args = loads(item)
    retval = func(*args)
except BaseException as exc:
    is_exception = True
    retval = exc
else:
    is_exception = False

try:
    _interpqueues.put(queue_id, (retval, is_exception), *QUEUE_UNPICKLE_ARGS)
except NotShareableError:
    retval = dumps(retval, HIGHEST_PROTOCOL)
    _interpqueues.put(queue_id, (retval, is_exception), *QUEUE_PICKLE_ARGS)
    z<string>�execc@r)r rr!r"r#r$cCs6t��|_tjdgt�R�|_t�|jd|ji�dS)Nr�queue_id)�
_interpretersr�_interpreter_id�
_interpqueuesrB�	_queue_id�set___main___attrsr'rrrr)`s

�r*cCst�|j�t�|j�dSr%)rGr,rHrErFr'rrrr,gsr-rr.rrr/c	Cs�ddl}|�||f|j�}tj|j|gt�R�t�|j	t
�}|r%t|��t�|j�}|dd�\\}}}|t
kr>|�|�}|rB|�|S)Nrr=)�pickle�dumps�HIGHEST_PROTOCOLrG�putrHrArErCrF�	_run_funcr�getr@�loads)	r(rrrJ�item�exc_infor2r3�fmtrrrr0ks
r4Nr5r6r7rrrrr ]s



c@s8eZdZUdZded<ddd�Zdd
d�Zddd�ZdS)r rr!r"r#r$cCstd��)Nz,subinterpreters require at least Python 3.13)�RuntimeErrorr'rrrr)�sr*rr.rrr/cCst�r%)�NotImplementedError)r(rrrrrr0�sr4cCsdSr%rr'rrrr,�sr-Nr5r6)r8r9r:r"r;r)r0r,rrrrr �s



��DEFAULT_CPU_COUNT�r/�PosArgsT�_available_workers�_default_interpreter_limiter�workers�
deque[Worker]r#r$cCs|D]}|��q|��dSr%)r,�clear)r\�workerrrr�
_stop_workers�s
r`��limiter�&Callable[[Unpack[PosArgsT]], T_Retval]�Unpack[PosArgsT]rb�CapacityLimiter | Nonec
�sf�|durt�}zt��}Wnty%t�}t�|�t�t|�Ynw|4IdH�z|�	�}Wnt
y?t�}YnwWd�IdHn1IdHsPwYz5tj
|j|||d�IdHWt�}|r�||djtkrrntj
|��j|d�IdH|sht�|_|�|�St�}|r�||djtkr�ntj
|��j|d�IdH|s�t�|_|�|�w)a�
    Call the given function with the given arguments in a subinterpreter.

    .. warning:: On Python 3.13, the :mod:`concurrent.interpreters` module was not yet
        available, so the code path for that Python version relies on an undocumented,
        private API. As such, it is recommended to not rely on this function for anything
        mission-critical on Python 3.13.

    :param func: a callable
    :param args: the positional arguments for the callable
    :param limiter: capacity limiter to use to limit the total number of subinterpreters
        running (if omitted, the default limiter is used)
    :return: the result of the call
    :raises BrokenWorkerInterpreter: if there's an internal error in a subinterpreter

    Nrar)�#current_default_interpreter_limiter�
_idle_workersrO�LookupErrorr�set�atexit�registerr`�pop�
IndexErrorr r
�run_syncr0r	r"�MAX_WORKER_IDLE_TIME�popleftr,�append)rrbr�idle_workersr_�nowrrrrn�sR�
�
��(�����rnrcCs<zt��WStytt��pt�}t�|�|YSw)z�
    Return the capacity limiter used by default to limit the number of concurrently
    running subinterpreters.

    Defaults to the number of CPU cores.

    :return: a capacity limiter object

    )r[rOrhr�os�	cpu_countrWrirarrrrf�s


�rf)rrrr)r\r]r#r$)rrcrrdrbrer#r/)r#r)2�
__future__rrjrt�sys�collectionsr�collections.abcr�typingrrr�r	r
�_core._exceptionsr�_core._synchronizationr�lowlevelr
�version_inforr�typing_extensions�concurrent.interpretersrrrr rGrEr>r;r?r@rArB�compilerNrWror/rYrgr[r`rnrfrrrr�<module>sX



�&�

�9