%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f>-���dZddlZddlZddlmZmZddlmZddlm	Z	m
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZmZddlmZddlmZmZmZd
�Zd�Zee�Gd�dej<��Zd�Z dgZ!y)a
Threaded select reactor

The threadedselectreactor is a specialized reactor for integrating with
arbitrary foreign event loop, such as those you find in GUI toolkits.

There are three things you'll need to do to use this reactor.

Install the reactor at the beginning of your program, before importing
the rest of Twisted::

    | from twisted.internet import _threadedselect
    | _threadedselect.install()

Interleave this reactor with your foreign event loop, at some point after
your event loop is initialized::

    | from twisted.internet import reactor
    | reactor.interleave(foreignEventLoopWakerFunction)
    | self.addSystemEventTrigger('after', 'shutdown', foreignEventLoopStop)

Instead of shutting down the foreign event loop directly, shut down the
reactor::

    | from twisted.internet import reactor
    | reactor.stop()

In order for Twisted to do its work in the main thread (the thread that
interleave is called from), a waker function is necessary.  The waker function
will be called from a "background" thread with one argument: func.
The waker function's purpose is to call func() from the main thread.
Many GUI toolkits ship with appropriate waker functions.
Some examples of this are wxPython's wx.callAfter (may be wxCallAfter in
older versions of wxPython) or PyObjC's PyObjCTools.AppHelper.callAfter.
These would be used in place of "foreignEventLoopWakerFunction" in the above
example.

The other integration point at which the foreign event loop and this reactor
must integrate is shutdown.  In order to ensure clean shutdown of Twisted,
you must allow for Twisted to come to a complete stop before quitting the
application.  Typically, you will do this by setting up an after shutdown
trigger to stop your foreign event loop, and call reactor.stop() where you
would normally have initiated the shutdown procedure for the foreign event
loop.  Shutdown functions that could be used in place of
"foreignEventloopStop" would be the ExitMainLoop method of the wxApp instance
with wxPython, or the PyObjCTools.AppHelper.stopEventLoop function.
�N)�EBADF�EINTR)�partial)�Empty�Queue)�Thread)�implementer)�	posixbase)�
IReactorFDSet)�_NO_FILEDESC�
_NO_FILENO)�_select)�failure�log�
threadablec�*�	||=y#t$rYywxYw�N)�KeyError)�dct�values  �B/usr/lib/python3/dist-packages/twisted/internet/_threadedselect.py�
dictRemoverEs ��
���J���
��
�s��	�c��|�r�)�es r�raiseExceptionrLs��
�G�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
eZd�Zd
�ZeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zy)�ThreadedSelectReactorzVA threaded select() based reactor - runs on all POSIX platforms and on
    Win32.
    c��tjd�i|_i|_t	�|_t	�|_d|_d|_tjj|�|jdd|j�y)N��after�shutdown)r�init�reads�writesr�
toThreadQueue�toMainThread�workerThread�	mainWakerr
�PosixReactorBase�__init__�addSystemEventTrigger�_mainLoopShutdown��selfs rr,zThreadedSelectReactor.__init__Vsk���������
����"�W���!�G��� �������"�"�+�+�D�1��"�"�7�J��8N�8N�Orc�8�|jj�yr)�waker�wakeUpr/s rr3zThreadedSelectReactor.wakeUpas���
�
���rc�l�tjj|g|��i|��}|j�|Sr)r
r+�	callLaterr3)r0�args�kw�tples    rr5zThreadedSelectReactor.callLateres0���)�)�3�3�D�F�4�F�2�F�����
��rc�x�|jj||f�|j�|j�yyr)r(�putr*)r0�msgr6s   r�_sendToMainz!ThreadedSelectReactor._sendToMainjs3�������s�D�k�*��>�>�%��N�N��&rc�>�|jj||f�yr)r'r:)r0�fnr6s   r�
_sendToThreadz#ThreadedSelectReactor._sendToThreados��������D�z�*rc���tjd�|jj�}|jj�}|jj�|jj�|j|f|j|ffD]-\}}|D]#}	t
j|g|g|gd�d||<�%�/y#t$rtjd|z�Y�LwxYw)Nz1Malformed file descriptor found.  Preening lists.rr!zbad descriptor %s)rr;r%�keysr&�clear�select�
BaseException)r0�readers�writers�selDict�selList�
selectables      r�_preenDescriptorsInThreadz/ThreadedSelectReactor._preenDescriptorsInThreadrs������C�D��*�*�/�/�#���+�+�"�"�$���
�
����������"&�*�*�g�!6����g�8N� O�	,��G�W�%�
,�
�,��M�M�:�,���z�l�A�N�+,�G�J�'�

,�	,��%�>��G�G�/�*�<�=�>�s�&C�!C/�.C/c���		|jj�\}}||��##t$rYyt$r)t	j
�}|j
d|�YywxYw)N�Failure)r'�get�
SystemExitrDrrLr<)r0r>r6�fs    r�_workerInThreadz%ThreadedSelectReactor._workerInThread�sf��	+���-�-�1�1�3���D��D�	����	���	+����!�A����Y��*�	+�s�$&�	A"�.A"�!A"c�`�|j}|j}		t|j�|j�g|�\}}}	|jd||�y#t$r'tj�|j�Yn�t$r'tj�|j�Ynst$rh}|jddvr
|s|sYd}~y�|jdtk(rYd}~y|jdtk(r|j�n�Yd}~nd}~wwxYw��)z�Run one iteration of the I/O monitor loop.

        This will run all selectables who had input or output readiness
        waiting for them.
        r)r�N�Notify)r%r&rrA�
ValueErrorr�errrJ�	TypeError�OSErrorr6rrr<)r0�timeoutr%r&�r�w�ignored�ses        r�_doSelectInThreadz'ThreadedSelectReactor._doSelectInThread�s����
�
�������
� '��
�
��f�k�k�m�R�� Q�
��1�g��2	
����1�a�(��1�
1����	��.�.�0��
1����	��.�.�0��
��7�7�1�:��'�!�F����W�W�Q�Z�5�(���W�W�Q�Z�5�(��2�2�4��5��
��s/�.A�-D+�
,D+�;D+�D&�D&�9(D&�&D+c	���|j}|j}|j}tj}|d|f|d|ffD]\}}}	|D]}
|
|	vr�||
||
||	��� y)N�doRead�doWrite)r%r&�_doReadOrWriter�callWithLogger)r0rYrZr%r&�_drdw�_logrun�selectables�methodrrIs           r�_process_Notifyz%ThreadedSelectReactor._process_Notify�s����
�
�������#�#���$�$��*+�X�u�)=��9�f�?U�(V�	D�$�K���)�
D�
��S�(���
�E�:�v�s�C�
D�	Drc�$�|j�yr)r)r0rOs  r�_process_Failurez&ThreadedSelectReactor._process_Failure�s��	���rc��|j�|jj�s6t|j��|_|jj	�yy)N)�target)r)�isAliverrP�startr/s r�ensureWorkerThreadz(ThreadedSelectReactor.ensureWorkerThread�sJ�����$�D�,=�,=�,E�,E�,G� &�d�.B�.B� C�D�����#�#�%�-Hrc��|j|j|�|j�|jj	�\}}t|d|z�|�y�N�	_process_)r?�_doIterationInThreadrnr(rM�getattr)r0rXr;r6s    r�doThreadIterationz'ThreadedSelectReactor.doThreadIteration�sR�����4�4�4�g�>����!��%�%�)�)�+�	��T�(���k�C�'�(�$�/rc#�>K�|jr�|j�|j�}|jxr|}|j|j|�d��|j
j
�\}}t|d|z�|�|jr��yy�wrp)�running�runUntilCurrentrXr?rrr(�
get_nowaitrs)r0�t2�tr;r6s     r�_interleavez!ThreadedSelectReactor._interleave�s������l�l�� � �"�����B����#��A����t�8�8�!�<��J��)�)�4�4�6�I�C��,�G�D�+��+�,�d�3��l�l�s�BB�Bc��|j|i|��|j�}||fd�}||_t|�|j	�y)a�
        interleave(waker) interleaves this reactor with the
        current application by moving the blocking parts of
        the reactor (select() in this case) to a separate
        thread.  This is typically useful for integration with
        GUI applications which have their own event loop
        already running.

        See the module docstring for more information.
        c�0�|tt|��yr)r�next)r2�loops  rr*z3ThreadedSelectReactor.interleave.<locals>.mainWaker�s���'�$��%�&rN)�startRunningr{r*r~rn)r0r2r6r7rr*s      r�
interleavez ThreadedSelectReactor.interleave�sM��	����4�&�2�&����!��!��	'�#����T�
����!rc��d|_|j�J|jtt�|j�		|jj�\}}�		|jj�\}}||jurtjd�n|tur|dturn||��[#t$rYnwxYw|jj�d|_��#t$rYywxYw)Nz'Iteration is still in the thread queue!r)r*r)r?rrNr3r(rxr�joinr'rrrr;)r0r;r6r>s    rr.z'ThreadedSelectReactor._mainLoopShutdown�s���������(����~�z�:��K�K�M�
�� $� 1� 1� <� <� >�I�C���
	���-�-�8�8�:���D���2�2�2��G�G�E�F��>�)�d�1�g��.C����I����
��
�����"�"�$� $�D����	��	�s$�B;�AC,�;	C�C�,	C8�7C8c��	t||��}t|dd�}|st}n|�dk(rt}|r|j|||dk(�yy#t$r.t	j
�d}t
j�Y�PwxYw)N�fileno���r!r_)	rsr
rrD�sys�exc_inforrU�_disconnectSelectable)r0rIrf�dict�why�handfns      rraz$ThreadedSelectReactor._doReadOrWrite	s���		�-�'�*�f�-�/�C��Z��4�8�F�� ����R��"����&�&�z�3��(�8J�K����	��,�,�.��#�C��G�G�I�	�s�7A�4B
�	B
c�r�|j|jj|d�|j�y)z@Add a FileDescriptor for notification of data available to read.r!N)r?r%�__setitem__r3�r0�readers  r�	addReaderzThreadedSelectReactor.addReaders'�����4�:�:�1�1�6�1�=����
rc�r�|j|jj|d�|j�y)zAAdd a FileDescriptor for notification of data available to write.r!N)r?r&r�r3�r0�writers  r�	addWriterzThreadedSelectReactor.addWriters'�����4�;�;�2�2�F�A�>����
rc�F�|jt|j|�y)z?Remove a Selectable for notification of data available to read.N)r?rr%r�s  r�removeReaderz"ThreadedSelectReactor.removeReader!s�����:�t�z�z�6�:rc�F�|jt|j|�y)z@Remove a Selectable for notification of data available to write.N)r?rr&r�s  r�removeWriterz"ThreadedSelectReactor.removeWriter%s�����:�t�{�{�F�;rc�N�|j|j|j�Sr)�
_removeAllr%r&r/s r�	removeAllzThreadedSelectReactor.removeAll)s�����t�z�z�4�;�;�7�7rc�H�t|jj��Sr)�listr%rAr/s r�
getReadersz ThreadedSelectReactor.getReaders,s���D�J�J�O�O�%�&�&rc�H�t|jj��Sr)r�r&rAr/s r�
getWritersz ThreadedSelectReactor.getWriters/s���D�K�K�$�$�&�'�'rc�b�tjj|�|j�y)z�
        Extend the base stop implementation to also wake up the select thread so
        that C{runUntilCurrent} notices the reactor should stop.
        N)r
r+�stopr3r/s rr�zThreadedSelectReactor.stop2s!��
	�"�"�'�'��-����
rc�H�|j|��|j�y)N)�installSignalHandlers)r��mainLoop)r0r�s  r�runzThreadedSelectReactor.run:s�����0E��F��
�
�rc���t�}|j|j�|jr$	|j	��|jr�#yy#t
$rYywxYwr)rr�r:rvrM�
StopIteration)r0�qs  rr�zThreadedSelectReactor.mainLoop>sO���G����������l�l�
������	��l�l��!�
��
�s�A�	A#�"A#N)T) �__name__�
__module__�__qualname__�__doc__r,r3r5r<r?rJrPr]rgrirrrnrt�doIterationr{r�r.rar�r�r�r�r�r�r�r�r�r�rrrrrPs����	P���
�
+�
,�	+�$)�LD��-��&�
0�$�K�4�"�*�0L��
�
;�<�8�'�(���rrc�6�t�}ddlm}||�|S)zDConfigure the twisted mainloop to be run using the select() reactor.r)�installReactor)r�twisted.internet.mainr�)�reactorr�s  r�installr�Hs��#�%�G�4��7���Nrr�)"r�rCr��errnorr�	functoolsr�queuerr�	threadingr�zope.interfacer	�twisted.internetr
�twisted.internet.interfacesr�twisted.internet.posixbaserr
�twisted.internet.selectreactorr�twisted.pythonrrrrrr+rr��__all__rrr�<module>r�sv��
.�`�
�����&�&�5�?�2�3�3�
��
�]��t�I�6�6�t��t�n��+�r

Zerion Mini Shell 1.0