%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/__pycache__/threadpool.cpython-312.pyc

�

Ϫ�f�*���dZddlmZddlmZmZddlmZmZm	Z	m
Z
mZddlmZm
Z
mZddlmZddlmZmZddlmZdd	lmZdd
lmZed�Zed�ZGd
�de
�ZGd�de�Ze�Z Gd�d�Z!y)z�
twisted.python.threadpool: a pool of threads to which we dispatch tasks.

In most cases you can just use C{reactor.callInThread} and friends
instead of creating a thread pool directly.
�)�annotations)�Thread�current_thread)�Any�Callable�List�Optional�TypeVar)�	ParamSpec�Protocol�	TypedDict)�pool)�context�log)�
deprecated)�Failure)�Version�_P�_Rc��eZdZdd�Zy)�_SupportsQsizec��y�N���selfs �;/usr/lib/python3/dist-packages/twisted/python/threadpool.py�qsizez_SupportsQsize.qsizes���N��return�int��__name__�
__module__�__qualname__rrrrrrs��rrc�"�eZdZUded<ded<y)�_Stater"�min�maxN)r$r%r&�__annotations__rrrr(r("s��	�H�	�Hrr(c�b�eZdZdZdZdZdZdZdZe	Z
eee
dddd	�d
��e��Zee�Z	d					dd�Zedd
��Zedd��Zedd��Zed d��ZeZd!d�Zd!d�Zd"d�Zd!d�Zd#d�Zd$d�Z								d%d�Z										d&d�Zd!d�Z 	d'					d(d�Z!d!d�Z"y))�
ThreadPoola�
    This class (hopefully) generalizes the functionality of a pool of threads
    to which work can be dispatched.

    L{callInThread} and L{stop} should only be called from a single thread.

    @ivar started: Whether or not the thread pool is currently running.
    @type started: L{bool}

    @ivar threads: List of workers currently running in this thread pool.
    @type threads: L{list}

    @ivar _pool: A hook for testing.
    @type _pool: callable compatible with L{_pool}
    ��FN�Twisted��rzthreading.current_thread)�version�replacementc���|dk\sJd��||ksJd��|�_|�_|�_g�_d�fd�}d�fd�}�j	||��_y)	ac
        Create a new threadpool.

        @param minthreads: minimum number of threads in the pool
        @type minthreads: L{int}

        @param maxthreads: maximum number of threads in the pool
        @type maxthreads: L{int}

        @param name: The name to give this threadpool; visible in log messages.
        @type name: native L{str}
        r�minimum is negative�minimum is greater than maximumc����j|d�j�i|��}�jj|�|S)N�name)�
threadFactory�
_generateName�threads�append)�a�kw�threadrs   �r�trackingThreadFactoryz2ThreadPool.__init__.<locals>.trackingThreadFactory`sJ���'�T�'�'����+�+�-��13��F�
�L�L����'��Mrc�6���jsy�jS)Nr)�startedr*rs�r�currentLimitz)ThreadPool.__init__.<locals>.currentLimitgs����<�<���8�8�OrN)r>rr?rr!rr )r)r*r9r<�_pool�_team)r�
minthreads�
maxthreadsr9rArDs`     r�__init__zThreadPool.__init__Jsf����Q��5� 5�5���Z�'�J�)J�J�'���������	�%'���	�	�
�Z�Z��.C�D��
rc�h�|jj�}|j|jzS)a
        For legacy compatibility purposes, return a total number of workers.

        @return: the current number of workers, both idle and busy (but not
            those that have been quit by L{ThreadPool.adjustPoolsize})
        @rtype: L{int}
        )rF�
statistics�idleWorkerCount�busyWorkerCount)r�statss  r�workerszThreadPool.workersns-���
�
�%�%�'���$�$�u�'<�'<�<�<rc�R�dg|jj�jzS)z�
        For legacy compatibility purposes, return the number of busy workers as
        expressed by a list the length of that number.

        @return: the number of workers currently processing a work item.
        @rtype: L{list} of L{None}
        N)rFrKrMrs r�workingzThreadPool.workingzs$���v��
�
�-�-�/�?�?�?�?rc�R�dg|jj�jzS)a,
        For legacy compatibility purposes, return the number of idle workers as
        expressed by a list the length of that number.

        @return: the number of workers currently alive (with an allocated
            thread) but waiting for new work.
        @rtype: L{list} of L{None}
        N)rFrKrLrs r�waiterszThreadPool.waiters�s$���v��
�
�-�-�/�?�?�?�?rc�*��G�fd�d�}|�S)z�
        For legacy compatibility purposes, return an object with a C{qsize}
        method that indicates the amount of work not yet allocated to a worker.

        @return: an object with a C{qsize} method.
        c���eZdZd�fd�Zy)�$ThreadPool._queue.<locals>.NotAQueuec�L���jj�jS)a
                Pretend to be a Python threading Queue and return the
                number of as-yet-unconsumed tasks.

                @return: the amount of backlogged work not yet dispatched to a
                    worker.
                @rtype: L{int}
                )rFrK�backloggedWorkCount)�qrs �rrz*ThreadPool._queue.<locals>.NotAQueue.qsize�s����z�z�,�,�.�B�B�BrNr r#rs�r�	NotAQueuerV�s	���	
CrrZr)rrZs` r�_queuezThreadPool._queue�s���
	C�
	C��{�rc���d|_d|_|j�|jj	�j
}|r|jj
|�yy)z'
        Start the threadpool.
        FTN)�joinedrC�adjustPoolsizerFrKrX�grow)r�backlogs  r�startzThreadPool.start�sN�������������*�*�'�'�)�=�=����J�J�O�O�G�$�rc�:�|jjd�y)z�
        Increase the number of available workers for the thread pool by 1, up
        to the maximum allowed by L{ThreadPool.max}.
        r2N)rFr_rs r�startAWorkerzThreadPool.startAWorker�s��
	
�
�
����rc�T�d|jxst|��d|j��S)z�
        Generate a name for a new pool thread.

        @return: A distinctive name for the thread.
        @rtype: native L{str}
        zPoolThread-�-)r9�idrOrs rr;zThreadPool._generateName�s)���T�Y�Y�2�"�T�(�3�1�T�\�\�N�C�Crc�:�|jjd�y)zn
        Decrease the number of available workers by 1, by quitting one as soon
        as it's idle.
        r2N)rF�shrinkrs r�stopAWorkerzThreadPool.stopAWorker�s��
	
�
�
���!�rc�t�t|d|�tj||j|j�y)N�__dict__)�setattrr-rIr)r*)r�states  r�__setstate__zThreadPool.__setstate__�s(����j�%�(����D�$�(�(�D�H�H�5rc�D�t|j|j��S)N)r)r*)r(r)r*rs r�__getstate__zThreadPool.__getstate__�s���$�(�(����1�1rc�2�|jd|g|��i|��y)a
        Call a callable object in a separate thread.

        @param func: callable object to be called in separate thread

        @param args: positional arguments to be passed to C{func}

        @param kw: keyword args to be passed to C{func}
        N)�callInThreadWithCallback)r�func�argsr?s    r�callInThreadzThreadPool.callInThread�s ��	&��%�%�d�D�>�4�>�2�>rc��������|jrytjj�jd�d�fd������fd��_|�_|jj��y)a$
        Call a callable object in a separate thread and call C{onResult} with
        the return value, or a L{twisted.python.failure.Failure} if the
        callable raises an exception.

        The callable is allowed to block, but the C{onResult} function must not
        block and should perform as little work as possible.

        A typical action for C{onResult} for a threadpool used with a Twisted
        reactor would be to schedule a L{twisted.internet.defer.Deferred} to
        fire in the main reactor thread using C{.callFromThread}.  Note that
        C{onResult} is called inside the separate thread, not inside the
        reactor thread.

        @param onResult: a callable with the signature C{(success, result)}.
            If the callable returns normally, C{onResult} is called with
            C{(True, result)} where C{result} is the return value of the
            callable.  If the callable throws an exception, C{onResult} is
            called with C{(False, failure)}.

            Optionally, C{onResult} may be L{None}, in which case it is not
            called at all.

        @param func: callable object to be called in separate thread

        @param args: positional arguments to be passed to C{func}

        @param kw: keyword arguments to be passed to C{func}
        N���c����	�j�}d}d�_�j��j||�d�_y|st	j
|�yy#t$rt�}d}Y�]wxYw)NTF)�theWork�
BaseExceptionr�onResultr�err)�result�ok�	inContexts  �rrz6ThreadPool.callInThreadWithCallback.<locals>.inContextsy���
�"�*�*�,����
!%�I���!�!�-��"�"�2�v�.�%)�	�"���������!�
� �����
�s�A�A3�2A3c�8��tj��g���i���Sr)r�call)rt�ctxrsr?s����r�<lambda>z5ThreadPool.callInThreadWithCallback.<locals>.<lambda>s%���G�L�L���%
��%
� "�%
�r�r!�None)	r]r�theContextTracker�currentContext�contextsryr{rF�do)rr{rsrtr?r�rs  ```@@rrrz#ThreadPool.callInThreadWithCallback�sX���H�;�;���'�'�6�6�8�A�A�"�E��
	 �$
�	��&�	���
�
�
�
�i� rc��d|_d|_|jj�|jD]}|j��y)z9
        Shutdown the threads in the threadpool.
        TFN)r]rCrF�quitr<�join)rr@s  r�stopzThreadPool.stop$s<���������
�
�����l�l�	�F��K�K�M�	rc���|�|j}|�|j}|dk\sJd��||ksJd��||_||_|jsy|j|jkDr2|jj|j|jz
�|j|jkr3|jj
|j|jz
�yy)z�
        Adjust the number of available threads by setting C{min} and C{max} to
        new values.

        @param minthreads: The new value for L{ThreadPool.min}.

        @param maxthreads: The new value for L{ThreadPool.max}.
        Nrr6r7)r)r*rCrOrFrhr_)rrGrHs   rr^zThreadPool.adjustPoolsize.s��������J������J��Q��5� 5�5���Z�'�J�)J�J�'��������|�|���<�<�$�(�(�"��J�J���d�l�l�T�X�X�5�6��<�<�$�(�(�"��J�J�O�O�D�H�H�t�|�|�3�4�#rc���tjd|j���tjd|j���tjd|j���y)zw
        Dump some plain-text informational messages to the log about the state
        of this L{ThreadPool}.
        z	waiters: z	workers: ztotal: N)r�msgrSrQr<rs r�	dumpStatszThreadPool.dumpStatsMsI��
	���)�D�L�L�>�*�+����)�D�L�L�>�*�+����'�$�,�,��(�)r)r.r/N)rGr"rHr"r9z
Optional[str]r )r!z
list[None])r!rr�)r!�str)rmr(r!r�)r!r()rszCallable[_P, object]rt�_P.argsr?�	_P.kwargsr!r�)
r{z&Optional[Callable[[bool, _R], object]]rszCallable[_P, _R]rtr�r?r�r!r�)NN)rG�
Optional[int]rHr�r!r�)#r$r%r&�__doc__r)r*r]rCr9rr:�staticmethodrrr�
currentThreadrErI�propertyrOrQrSr[rYrarcr;rirnrprurrr�r^r�rrrr-r-*s���� �C�
�C�
�F��G��D��M� �	
�
��I�r�1�a�0�2�	
��	��M�
���E�PT�"E��"E�/2�"E�?L�"E�H�	=��	=��@��@��	@��	@�����,	�A�
%��D��6�2�?�(�?�18�?�@I�?�	
�?�?!�8�?!��?!��	?!�
�?!�
�
?!�B�MQ�5�'�5�<I�5�	
�5�>*rr-N)"r��
__future__r�	threadingrr�typingrrrr	r
rrr
�twisted._threadsrrE�twisted.pythonrr�twisted.python.deprecater�twisted.python.failurer�twisted.python.versionsrrrrr(�object�
WorkerStopr-rrr�<module>r�sl��
�#�,�9�9�1�1�*�'�/�*�+��t�_���T�]���X��

�Y�
�
�X�
�j*�j*r

Zerion Mini Shell 1.0