HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/anyio/__pycache__/to_interpreter.cpython-310.pyc
o

���g��@s\UddlmZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZmZddlmZmZdd	lmZdd
lmZddlmZejdkr[dd
lmZmZndd
lmZmZdZded<dZded<dZ ded<dZ!ded<dZ"ed�Z#ed�Z$eedd�Z%eed�Z&Gdd�d�Z'd.d d!�Z(dd"�d/d)d*�Z)d0d,d-�Z*dS)1�)�annotationsN)�deque)�Callable)�dedent)�Any�Final�TypeVar�)�current_time�	to_thread)�BrokenWorkerIntepreter)�CapacityLimiter)�RunVar)��)�TypeVarTuple�Unpack�r�UNBOUND�
FMT_UNPICKLED�FMT_PICKLED��DEFAULT_CPU_COUNT��T_Retval�PosArgsT�Worker�_available_workers�_default_interpreter_limiterc@sneZdZUeed�dd�ZdZded<dZded	<d
ed<d
ed<d dd�Z	d dd�Z
d!dd�Zd"dd�ZdS)#ra�
        import _interpqueues as queues
        import _interpreters as interpreters
        from pickle import loads, dumps, HIGHEST_PROTOCOL

        item = queues.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:
            queues.put(queue_id, (retval, is_exception), FMT_UNPICKLED, UNBOUND)
        except interpreters.NotShareableError:
            retval = dumps(retval, HIGHEST_PROTOCOL)
            queues.put(queue_id, (retval, is_exception), FMT_PICKLED, UNBOUND)
        z<string>�execr�float�	last_usedF�bool�_initialized�int�_interpreter_id�	_queue_id�return�NonecCsNddl}ddl}|��|_|�dtt�|_d|_|�|j|jt	ttd��dS)NrrT)�queue_idrrr)
�
_interpqueues�
_interpreters�creater%rrr&r#�set___main___attrsr��self�queues�interpreters�r2�?/usr/local/lib/python3.10/dist-packages/anyio/to_interpreter.py�
initializeFs
��zWorker.initializecCs6ddl}ddl}|jr|�|j�|�|j�dSdS)Nr)r*r+r#�destroyr%r&r.r2r2r3r5Ws�zWorker.destroy�func�Callable[..., T_Retval]�args�
tuple[Any]�tuple[Any, bool]c
Cs�ddl}ddl}|js|��t�||ftj�}|�|j|t	t
�|�|j|j
�}r/t|��|�|j�dd�\\}}}	|	t	krFt�|�}||fS)Nrr)r*r+r#r4�pickle�dumps�HIGHEST_PROTOCOL�putr&rrrr%�	_run_funcr�get�loads)
r/r6r8r0r1�payload�exc_info�res�is_exception�fmtr2r2r3�_call_s
zWorker._call�limiterr
rc�s,�tj|j|||d�IdH\}}|r|�|S)N�rH)r�run_syncrG)r/r6r8rH�resultrEr2r2r3�callxs��zWorker.callN)r'r()r6r7r8r9r'r:)r6r7r8r9rHr
r'r)
�__name__�
__module__�__qualname__�compilerr?r!�__annotations__r#r4r5rGrLr2r2r2r3r%s
�


�workers�
deque[Worker]r'r(cCs|D]}|��q|��dS)N)r5�clear)rR�workerr2r2r3�
_stop_workers�s
rVrIr6�&Callable[[Unpack[PosArgsT]], T_Retval]r8�Unpack[PosArgsT]rH�CapacityLimiter | Nonec
�sr�tjdkr
td��|durt�}zt��}Wnty.t�}t�|�t	�
t|�Ynw|4IdH�z|��}Wnt
yHt�}YnwWd�IdHn1IdHsYwYz2|�|||�IdHWt�}|r�||djtkrxntj|��j|d�IdH|snt�|_|�|�St�}|r�||djtkr�ntj|��j|d�IdH|s�t�|_|�|�w)aF
    Call the given function with the given arguments in a subinterpreter.

    If the ``cancellable`` option is enabled and the task waiting for its completion is
    cancelled, the call will still run its course but its return value (or any raised
    exception) will be ignored.

    .. warning:: This feature is **experimental**. The upstream interpreter API has not
        yet been finalized or thoroughly tested, so don't rely on this for anything
        mission critical.

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

    )r�
z,subinterpreters require at least Python 3.13NrrI)�sys�version_info�RuntimeError�#current_default_interpreter_limiter�
_idle_workersr@�LookupErrorr�set�atexit�registerrV�pop�
IndexErrorrrLr
r!�MAX_WORKER_IDLE_TIMErrJ�popleftr5�append)r6rHr8�idle_workersrU�nowr2r2r3rJ�sL�

�
��(����rJr
cCs<zt��WStytt��pt�}t�|�|YSw)z�
    Return the capacity limiter that is used by default to limit the number of
    concurrently running subinterpreters.

    Defaults to the number of CPU cores.

    :return: a capacity limiter object

    )rr@r`r
�os�	cpu_countrrarIr2r2r3r^�s


�r^)rRrSr'r()r6rWr8rXrHrYr'r)r'r
)+�
__future__rrbrkr;r[�collectionsr�collections.abcr�textwrapr�typingrrr�r
r�_core._exceptionsr�_core._synchronizationr
�lowlevelrr\rr�typing_extensionsrrQrrrrfrrr_rrrVrJr^r2r2r2r3�<module>s>
�
e
�: