%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/internet/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/internet/test/__pycache__/test_threads.cpython-312.pyc

�

Ϫ�f����dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZGd	�d
e�Ze�j#ej%��y)z2
Tests for implementations of L{IReactorThreads}.
�N)�ref)�IReactorThreads)�ReactorBuilder)�isInIOThread)�
ThreadPool)�Versionc�R�eZdZdZefZd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zy)
�ThreadTestsBuilderzD
    Builder for defining tests relating to L{IReactorThreads}.
    c�����g�|j���j��|j�t�|j	�j
d����fd�}�j
|�|j�d�|j�dd�|j	�dd�|j�jd�y	)
z�
        C{reactor.getThreadPool()} returns an instance of L{ThreadPool} which
        starts when C{reactor.run()} is called and stops before it returns.
        z(Pool should not start before reactor.runc����j�j��j�j��j�y�N)�append�started�joined�stop)�pool�reactor�states����D/usr/lib/python3/dist-packages/twisted/internet/test/test_threads.py�fz0ThreadTestsBuilder.test_getThreadPool.<locals>.f's,����L�L����&��L�L����%��L�L�N��rz#Pool should start after reactor.run�z-Pool should not be joined before reactor.stopz0Pool should be stopped after reactor.run returnsN)
�buildReactor�
getThreadPool�assertIsInstancer�assertFalser�callWhenRunning�
runReactor�
assertTruer)�selfrrrrs  @@@r�test_getThreadPoolz%ThreadTestsBuilder.test_getThreadPools����
���#�#�%���$�$�&�����d�J�/�������'Q�R�	�	����"������#�����a��"G�H�����q��#R�S�������%W�Xrc��|j�}|jd�|j�}|j|jd�y)zm
        C{reactor.suggestThreadPoolSize()} sets the maximum size of the reactor
        threadpool.
        �N)r�suggestThreadPoolSizer�assertEqual�max)r!rrs   r�test_suggestThreadPoolSizez-ThreadTestsBuilder.test_suggestThreadPoolSize4sB��
�#�#�%���%�%�b�)��$�$�&��������2�&rc���|j���fd�}�jd�j|��j�}|j	�d��j�}|j||z
dk�y)aR
        A function scheduled with L{IReactorThreads.callFromThread} invoked
        from a delayed call is run immediately in the next reactor iteration.

        When invoked from the reactor thread, previous implementations of
        L{IReactorThreads.callFromThread} would skip the pipe/socket based wake
        up step, assuming the reactor would wake up on its own.  However, this
        resulted in the reactor not noticing an insert into the thread queue at
        the right time (in this case, after the thread queue has been processed
        for that reactor iteration).
        c�&���j�yr
)r)rs�r�
threadCallzAThreadTestsBuilder.test_delayedCallFromThread.<locals>.threadCallLs����L�L�Nrr�<�N)r�	callLater�callFromThread�secondsrr )r!r+�before�afterrs    @r�test_delayedCallFromThreadz-ThreadTestsBuilder.test_delayedCallFromThread>so����#�#�%��	�	���!�W�3�3�Z�@����"�������$����!��$	
�������+�,rc����|j��g���fd�}�jd�j�j|�|j	�d�|j�t
j�g�y)z�
        A function scheduled with L{IReactorThreads.callFromThread} invoked
        from another thread is run in the reactor thread.
        c�l���jtj���j�yr
)r�	threading�current_threadr)r�results��rr+z:ThreadTestsBuilder.test_callFromThread.<locals>.threadCallps!����M�M�)�2�2�4�5��L�L�Nrr�N)rr.�callInThreadr/rr&r6r7)r!r+rr8s  @@r�test_callFromThreadz&ThreadTestsBuilder.test_callFromThreadhsi���
�#�#�%����	�	���!�W�1�1�7�3I�3I�:�V������#�����)�":�":�"<�!=�>rc��|j�}t|j��}|j|j�|j|�t
j�|j|��y)a0
        When the reactor stops, L{ReactorBase._stopThreadPool} drops the
        reactor's direct reference to its internal threadpool and removes
        the associated startup and shutdown triggers.

        This is the case of the thread pool being created before the reactor
        is run.
        N)	rrrrrr�gc�collect�assertIsNone)r!r�
threadpools   r�test_stopThreadPoolz&ThreadTestsBuilder.test_stopThreadPoolys\���#�#�%����.�.�0�1�
�������-����� �
�
�
�����*�,�'rc�����|j��g���fd�}�j|�|j��tj�|j�d��y)a�
        We must handle the case of shutting down the thread pool when it was
        started after the reactor was run in a special way.

        Some implementation background: The thread pool is started with
        callWhenRunning, which only returns a system trigger ID when it is
        invoked before the reactor is started.

        This is the case of the thread pool being created after the reactor
        is started.
        c�v���jt�j����j�yr
)rrrr)r�threadPoolRefss��r�acquireThreadPoolz[ThreadTestsBuilder.test_stopThreadPoolWhenStartedAfterReactorRan.<locals>.acquireThreadPool�s(����!�!�#�g�&;�&;�&=�">�?��L�L�NrrN)rrrr=r>r?)r!rErrDs  @@r�-test_stopThreadPoolWhenStartedAfterReactorRanz@ThreadTestsBuilder.test_stopThreadPoolWhenStartedAfterReactorRan�s\����#�#�%����	�	��� 1�2����� �
�
�
�����+�.��+�-�.rc���|j�}t|j��}|jd�t	j
�|j
|��y)a[
        When the reactor has its shutdown event fired before it is run, the
        thread pool is completely destroyed.

        For what it's worth, the reason we support this behavior at all is
        because Trial does this.

        This is the case of the thread pool being created without the reactor
        being started at al.
        �shutdownN)rrr�fireSystemEventr=r>r?)r!r�
threadPoolRefs   r�,test_cleanUpThreadPoolEvenBeforeReactorIsRunz?ThreadTestsBuilder.test_cleanUpThreadPoolEvenBeforeReactorIsRun�sL���#�#�%���G�1�1�3�4�
����
�+�
�
�
�����-�/�*rc����g�|j����fd�}�j|�|j��|jdg��y)z�
        The reactor registers itself as the I/O thread when it runs so that
        L{twisted.python.threadable.isInIOThread} returns C{True} if it is
        called in the thread the reactor is running in.
        c�X���jt���j�yr
)rrr�r�resultss��r�checkz3ThreadTestsBuilder.test_isInIOThread.<locals>.check�s����N�N�<�>�*��L�L�NrTN)rrrr&�r!rPrrOs  @@r�test_isInIOThreadz$ThreadTestsBuilder.test_isInIOThread�sK������#�#�%��	�	����&����� ����$���)rc����g�|j����fd�}�j|�|j��|jdg��y)z�
        The reactor registers itself as the I/O thread when it runs so that
        L{twisted.python.threadable.isInIOThread} returns C{False} if it is
        called in a different thread than the reactor is running in.
        c�n���jt���j�j�yr
)rrr/rrNs��rrPz6ThreadTestsBuilder.test_isNotInIOThread.<locals>.check�s#����N�N�<�>�*��"�"�7�<�<�0rFN)rr:rr&rQs  @@r�test_isNotInIOThreadz'ThreadTestsBuilder.test_isNotInIOThread�sK������#�#�%��	1�	���U�#����� ����%��'�*rc�b�|jtdddd�dftj��y)N�Twisted�rrzthreading.current_thread)�versionr)�callDeprecatedrr�
currentThread)r!s r�&test_threadPoolCurrentThreadDeprecatedz9ThreadTestsBuilder.test_threadPoolCurrentThreadDeprecated�s6������	�2�q�!�,�*���&�&�	�	
rN)�__name__�
__module__�__qualname__�__doc__r�requiredInterfacesr"r(r3r;rArFrKrRrUr\�rrr
r
sF���*�+��Y�2'�(-�T?�"(� /�0+�"*�"+�"
rr
)r`r=r6�weakrefr�twisted.internet.interfacesr�#twisted.internet.test.reactormixinsr�twisted.python.threadabler�twisted.python.threadpoolr�twisted.python.versionsrr
�globals�update�makeTestCaseClassesrbrr�<module>rlsO���

���7�>�2�0�+�G
��G
�T�	���#�7�7�9�:r

Zerion Mini Shell 1.0