HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/site-packages/zmq/eventloop/minitornado/__pycache__/ioloop.cpython-36.pyc
3

VS�_���@s�dZddlmZmZmZmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlmZmZddlmZmZddlmZddlmZmZmZyddl Z Wne!k
r�dZ YnXyddl"Z"Wne!k
�rddl#Z"YnXdd	l$m%Z%m&Z&d
Z'Gdd�de(�Z)Gd
d�de�Z*Gdd�de*�Z+Gdd�de,�Z-Gdd�de,�Z.dS)a�An I/O event loop for non-blocking sockets.

Typical applications will use a single `IOLoop` object, in the
`IOLoop.instance` singleton.  The `IOLoop.start` method should usually
be called at the end of the ``main()`` function.  Atypical applications may
use more than one `IOLoop`, such as one `IOLoop` per thread, or per `unittest`
case.

In addition to I/O events, the `IOLoop` can also schedule time-based events.
`IOLoop.add_timeout` is a non-blocking alternative to `time.sleep`.
�)�absolute_import�division�print_function�with_statementN�)�TracebackFuture�	is_future)�app_log�gen_log)�
stack_context)�Configurable�errno_from_exception�timedelta_to_seconds)�set_close_exec�Wakerg �@c@seZdZdS)�TimeoutErrorN)�__name__�
__module__�__qualname__�rr�/usr/lib64/python3.6/ioloop.pyrCsrc@s�eZdZdZdZdZdZdZdZdZ	dRZ
dSZd
ZeZ
eZeeBZej�Zej�Zedd��Zed
d��Zdd�Zedd��ZedTdd��Zdd�Zedd��Zedd��Zedd��ZdUdd �Z dVd"d#�Z!d$d%�Z"d&d'�Z#d(d)�Z$d*d+�Z%d,d-�Z&d.d/�Z'd0d1�Z(d2d3�Z)d4d5�Z*dWd6d7�Z+d8d9�Z,d:d;�Z-d<d=�Z.d>d?�Z/d@dA�Z0dBdC�Z1dDdE�Z2dFdG�Z3dHdI�Z4dJdK�Z5dLdM�Z6dNdO�Z7dPdQ�Z8dS)X�IOLoopa�A level-triggered I/O loop.

    We use ``epoll`` (Linux) or ``kqueue`` (BSD and Mac OS X) if they
    are available, or else we fall back on select(). If you are
    implementing a system that needs to handle thousands of
    simultaneous connections, you should use a system that supports
    either ``epoll`` or ``kqueue``.

    Example usage for a simple TCP server:

    .. testcode::

        import errno
        import functools
        import tornado.ioloop
        import socket

        def connection_ready(sock, fd, events):
            while True:
                try:
                    connection, address = sock.accept()
                except socket.error as e:
                    if e.args[0] not in (errno.EWOULDBLOCK, errno.EAGAIN):
                        raise
                    return
                connection.setblocking(0)
                handle_connection(connection, address)

        if __name__ == '__main__':
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            sock.setblocking(0)
            sock.bind(("", port))
            sock.listen(128)

            io_loop = tornado.ioloop.IOLoop.current()
            callback = functools.partial(connection_ready, sock)
            io_loop.add_handler(sock.fileno(), callback, io_loop.READ)
            io_loop.start()

    .. testoutput::
       :hide:

    By default, a newly-constructed `IOLoop` becomes the thread's current
    `IOLoop`, unless there already is a current `IOLoop`. This behavior
    can be controlled with the ``make_current`` argument to the `IOLoop`
    constructor: if ``make_current=True``, the new `IOLoop` will always
    try to become current and it raises an error if there is already a
    current instance. If ``make_current=False``, the new `IOLoop` will
    not try to become current.

    .. versionchanged:: 4.2
       Added the ``make_current`` keyword argument to the `IOLoop`
       constructor.
    r����i ��rc
Cs4ttd�s.tj�ttd�s$t�t_WdQRXtjS)a1Returns a global `IOLoop` instance.

        Most applications have a single, global `IOLoop` running on the
        main thread.  Use this method to get this instance from
        another thread.  In most other cases, it is better to use `current()`
        to get the current thread's `IOLoop`.
        �	_instanceN)�hasattrr�_instance_lockrrrrr�instance�s
	

zIOLoop.instancecCs
ttd�S)z8Returns true if the singleton instance has been created.r)rrrrrr�initialized�szIOLoop.initializedcCstj�st�|t_dS)z�Installs this `IOLoop` object as the singleton instance.

        This is normally not necessary as `instance()` will create
        an `IOLoop` on demand, but you may want to call `install` to use
        a custom subclass of `IOLoop`.
        N)rr"�AssertionErrorr)�selfrrr�install�szIOLoop.installcCsttd�rt`dS)zKClear the global `IOLoop` instance.

        .. versionadded:: 4.0
        rN)rrrrrrr�clear_instance�s
zIOLoop.clear_instanceTcCs&ttjdd�}|dkr"|r"tj�S|S)a�Returns the current thread's `IOLoop`.

        If an `IOLoop` is currently running or has been marked as
        current by `make_current`, returns that instance.  If there is
        no current `IOLoop`, returns `IOLoop.instance()` (i.e. the
        main thread's `IOLoop`, creating one if necessary) if ``instance``
        is true.

        In general you should use `IOLoop.current` as the default when
        constructing an asynchronous object, and use `IOLoop.instance`
        when you mean to communicate to the main thread from a different
        one.

        .. versionchanged:: 4.1
           Added ``instance`` argument to control the fallback to
           `IOLoop.instance()`.
        r!N)�getattrr�_currentr!)r!�currentrrrr)�szIOLoop.currentcCs|tj_dS)a�Makes this the `IOLoop` for the current thread.

        An `IOLoop` automatically becomes current for its thread
        when it is started, but it is sometimes useful to call
        `make_current` explicitly before starting the `IOLoop`,
        so that code run at startup time can find the right
        instance.

        .. versionchanged:: 4.1
           An `IOLoop` created while there is no current `IOLoop`
           will automatically become current.
        N)rr(r!)r$rrr�make_current�s
zIOLoop.make_currentcCsdtj_dS)N)rr(r!rrrr�
clear_current�szIOLoop.clear_currentcCstS)N)r)�clsrrr�configurable_base�szIOLoop.configurable_basecCs:ddlm}|Sttd�r*ddlm}|Sddlm	}|S)Nr)�	ZMQIOLoopZepoll)�EPollIOLoopZkqueue)�KQueueIOLoop)�SelectIOLoop)
Zzmq.eventloop.ioloopr.r�selectZtornado.platform.epollr/Ztornado.platform.kqueuer0Ztornado.platform.selectr1)r,r.r/r0r1rrr�configurable_default�s
zIOLoop.configurable_defaultNcCsJ|dkr"tjdd�dkrF|j�n$|rFtjdd�dk	r>td��|j�dS)NF)r!zcurrent IOLoop already exists)rr)r*�RuntimeError)r$r*rrr�
initialize�s
zIOLoop.initializeFcCs
t��dS)a�Closes the `IOLoop`, freeing any resources used.

        If ``all_fds`` is true, all file descriptors registered on the
        IOLoop will be closed (not just the ones created by the
        `IOLoop` itself).

        Many applications will only use a single `IOLoop` that runs for the
        entire lifetime of the process.  In that case closing the `IOLoop`
        is not necessary since everything will be cleaned up when the
        process exits.  `IOLoop.close` is provided mainly for scenarios
        such as unit tests, which create and destroy a large number of
        ``IOLoops``.

        An `IOLoop` must be completely stopped before it can be closed.  This
        means that `IOLoop.stop()` must be called *and* `IOLoop.start()` must
        be allowed to return before attempting to call `IOLoop.close()`.
        Therefore the call to `close` will usually appear just after
        the call to `start` rather than near the call to `stop`.

        .. versionchanged:: 3.1
           If the `IOLoop` implementation supports non-integer objects
           for "file descriptors", those objects will have their
           ``close`` method when ``all_fds`` is true.
        N)�NotImplementedError)r$�all_fdsrrr�closeszIOLoop.closecCs
t��dS)a�Registers the given handler to receive the given events for ``fd``.

        The ``fd`` argument may either be an integer file descriptor or
        a file-like object with a ``fileno()`` method (and optionally a
        ``close()`` method, which may be called when the `IOLoop` is shut
        down).

        The ``events`` argument is a bitwise or of the constants
        ``IOLoop.READ``, ``IOLoop.WRITE``, and ``IOLoop.ERROR``.

        When an event occurs, ``handler(fd, events)`` will be run.

        .. versionchanged:: 4.0
           Added the ability to pass file-like objects in addition to
           raw file descriptors.
        N)r6)r$�fd�handler�eventsrrr�add_handlerszIOLoop.add_handlercCs
t��dS)z�Changes the events we listen for ``fd``.

        .. versionchanged:: 4.0
           Added the ability to pass file-like objects in addition to
           raw file descriptors.
        N)r6)r$r9r;rrr�update_handler1szIOLoop.update_handlercCs
t��dS)z�Stop listening for events on ``fd``.

        .. versionchanged:: 4.0
           Added the ability to pass file-like objects in addition to
           raw file descriptors.
        N)r6)r$r9rrr�remove_handler:szIOLoop.remove_handlercCs
t��dS)a�Sends a signal if the `IOLoop` is blocked for more than
        ``s`` seconds.

        Pass ``seconds=None`` to disable.  Requires Python 2.6 on a unixy
        platform.

        The action parameter is a Python signal handler.  Read the
        documentation for the `signal` module for more information.
        If ``action`` is None, the process will be killed if it is
        blocked for too long.
        N)r6)r$�seconds�actionrrr�set_blocking_signal_thresholdCsz$IOLoop.set_blocking_signal_thresholdcCs|j||j�dS)z�Logs a stack trace if the `IOLoop` is blocked for more than
        ``s`` seconds.

        Equivalent to ``set_blocking_signal_threshold(seconds,
        self.log_stack)``
        N)rA�	log_stack)r$r?rrr�set_blocking_log_thresholdQsz!IOLoop.set_blocking_log_thresholdcCs tjd|jdjtj|���dS)z|Signal handler to log the stack trace of the current thread.

        For use with `set_blocking_signal_threshold`.
        z#IOLoop blocked for %f seconds in
%s�N)r
Zwarning�_blocking_signal_threshold�join�	traceback�format_stack)r$�signal�framerrrrBZszIOLoop.log_stackcCs
t��dS)z�Starts the I/O loop.

        The loop will run until one of the callbacks calls `stop()`, which
        will make the loop stop after the current event iteration completes.
        N)r6)r$rrr�startcszIOLoop.startcCs0ttj�jtjd�jtjd�jg�s,tj�dS)a�The IOLoop catches and logs exceptions, so it's
        important that log output be visible.  However, python's
        default behavior for non-root loggers (prior to python
        3.2) is to print an unhelpful "no handlers could be
        found" message rather than the actual log entry, so we
        must explicitly configure logging if we've made it this
        far without anything.

        This method should be called from start() in subclasses.
        �tornadoztornado.applicationN)�any�loggingZ	getLoggerZhandlersZbasicConfig)r$rrr�_setup_loggingks

zIOLoop._setup_loggingcCs
t��dS)aAStop the I/O loop.

        If the event loop is not currently running, the next call to `start()`
        will return immediately.

        To use asynchronous methods from otherwise-synchronous code (such as
        unit tests), you can start and stop the event loop like this::

          ioloop = IOLoop()
          async_method(ioloop=ioloop, callback=ioloop.stop)
          ioloop.start()

        ``ioloop.start()`` will return after ``async_method`` has run
        its callback, whether that callback was invoked before or
        after ``ioloop.start``.

        Note that even after `stop` has been called, the `IOLoop` is not
        completely stopped until `IOLoop.start` has also returned.
        Some work that was scheduled before the call to `stop` may still
        be run before the `IOLoop` shuts down.
        N)r6)r$rrr�stop{szIOLoop.stopcs|dg����fdd�}�j|�|dk	r>�j�j�|�j�}�j�|dk	rX�j|��dj�sptd|���dj�S)aStarts the `IOLoop`, runs the given function, and stops the loop.

        The function must return either a yieldable object or
        ``None``. If the function returns a yieldable object, the
        `IOLoop` will run until the yieldable is resolved (and
        `run_sync()` will return the yieldable's result). If it raises
        an exception, the `IOLoop` will stop and the exception will be
        re-raised to the caller.

        The keyword-only argument ``timeout`` may be used to set
        a maximum duration for the function.  If the timeout expires,
        a `TimeoutError` is raised.

        This method is useful in conjunction with `tornado.gen.coroutine`
        to allow asynchronous calls in a ``main()`` function::

            @gen.coroutine
            def main():
                # do stuff...

            if __name__ == '__main__':
                IOLoop.current().run_sync(main)

        .. versionchanged:: 4.3
           Returning a non-``None``, non-yieldable value is now an error.
        Nc
s�y&��}|dk	r$ddlm}||�}Wn0tk
rVt��d<�djtj��Yn,Xt|�rj|�d<nt��d<�dj|��j	�d�fdd��dS)Nr)�convert_yieldedcs�j�S)N)rP)�future)r$rr�<lambda>�sz.IOLoop.run_sync.<locals>.run.<locals>.<lambda>)
Ztornado.genrQ�	ExceptionrZset_exc_info�sys�exc_inforZ
set_result�
add_future)�resultrQ)�func�future_cellr$rr�run�s


zIOLoop.run_sync.<locals>.runrz$Operation timed out after %s seconds)	�add_callback�add_timeout�timerPrK�remove_timeout�donerrX)r$rY�timeoutr[Ztimeout_handler)rYrZr$r�run_sync�s

zIOLoop.run_synccCstj�S)aReturns the current time according to the `IOLoop`'s clock.

        The return value is a floating-point number relative to an
        unspecified time in the past.

        By default, the `IOLoop`'s time function is `time.time`.  However,
        it may be configured to use e.g. `time.monotonic` instead.
        Calls to `add_timeout` that pass a number instead of a
        `datetime.timedelta` should use this function to compute the
        appropriate time, so they can work no matter what time function
        is chosen.
        )r^)r$rrrr^�s
zIOLoop.timecOs\t|tj�r |j||f|�|�St|tj�rL|j|j�t|�|f|�|�Std|��dS)a�Runs the ``callback`` at the time ``deadline`` from the I/O loop.

        Returns an opaque handle that may be passed to
        `remove_timeout` to cancel.

        ``deadline`` may be a number denoting a time (on the same
        scale as `IOLoop.time`, normally `time.time`), or a
        `datetime.timedelta` object for a deadline relative to the
        current time.  Since Tornado 4.0, `call_later` is a more
        convenient alternative for the relative case since it does not
        require a timedelta object.

        Note that it is not safe to call `add_timeout` from other threads.
        Instead, you must use `add_callback` to transfer control to the
        `IOLoop`'s thread, and then call `add_timeout` from there.

        Subclasses of IOLoop must implement either `add_timeout` or
        `call_at`; the default implementations of each will call
        the other.  `call_at` is usually easier to implement, but
        subclasses that wish to maintain compatibility with Tornado
        versions prior to 4.0 must use `add_timeout` instead.

        .. versionchanged:: 4.0
           Now passes through ``*args`` and ``**kwargs`` to the callback.
        zUnsupported deadline %rN)	�
isinstance�numbers�Real�call_at�datetimeZ	timedeltar^r�	TypeError)r$�deadline�callback�args�kwargsrrrr]�szIOLoop.add_timeoutcOs|j|j�||f|�|�S)a�Runs the ``callback`` after ``delay`` seconds have passed.

        Returns an opaque handle that may be passed to `remove_timeout`
        to cancel.  Note that unlike the `asyncio` method of the same
        name, the returned object does not have a ``cancel()`` method.

        See `add_timeout` for comments on thread-safety and subclassing.

        .. versionadded:: 4.0
        )rfr^)r$Zdelayrjrkrlrrr�
call_later�szIOLoop.call_latercOs|j||f|�|�S)a�Runs the ``callback`` at the absolute time designated by ``when``.

        ``when`` must be a number using the same reference point as
        `IOLoop.time`.

        Returns an opaque handle that may be passed to `remove_timeout`
        to cancel.  Note that unlike the `asyncio` method of the same
        name, the returned object does not have a ``cancel()`` method.

        See `add_timeout` for comments on thread-safety and subclassing.

        .. versionadded:: 4.0
        )r])r$ZwhenrjrkrlrrrrfszIOLoop.call_atcCs
t��dS)z�Cancels a pending timeout.

        The argument is a handle as returned by `add_timeout`.  It is
        safe to call `remove_timeout` even if the callback has already
        been run.
        N)r6)r$rarrrr_szIOLoop.remove_timeoutcOs
t��dS)a3Calls the given callback on the next I/O loop iteration.

        It is safe to call this method from any thread at any time,
        except from a signal handler.  Note that this is the **only**
        method in `IOLoop` that makes this thread-safety guarantee; all
        other interaction with the `IOLoop` must be done from that
        `IOLoop`'s thread.  `add_callback()` may be used to transfer
        control from other threads to the `IOLoop`'s thread.

        To add a callback from a signal handler, see
        `add_callback_from_signal`.
        N)r6)r$rjrkrlrrrr\!s
zIOLoop.add_callbackcOs
t��dS)aSCalls the given callback on the next I/O loop iteration.

        Safe for use from a Python signal handler; should not be used
        otherwise.

        Callbacks added with this method will be run without any
        `.stack_context`, to avoid picking up the context of the function
        that was interrupted by the signal.
        N)r6)r$rjrkrlrrr�add_callback_from_signal0s
zIOLoop.add_callback_from_signalc
Os*tj��|j|f|�|�WdQRXdS)agCalls the given callback on the next IOLoop iteration.

        Unlike all other callback-related methods on IOLoop,
        ``spawn_callback`` does not associate the callback with its caller's
        ``stack_context``, so it is suitable for fire-and-forget callbacks
        that should not interfere with the caller.

        .. versionadded:: 4.0
        N)r�NullContextr\)r$rjrkrlrrr�spawn_callback<s

zIOLoop.spawn_callbackcs.t|�st�tj���|j��fdd��dS)z�Schedules a callback on the ``IOLoop`` when the given
        `.Future` is finished.

        The callback is invoked with one argument, the
        `.Future`.
        cs�j�|�S)N)r\)rR)rjr$rrrSSsz#IOLoop.add_future.<locals>.<lambda>N)rr#r�wrapZadd_done_callback)r$rRrjr)rjr$rrWIs
zIOLoop.add_futurecCsxyT|�}|dk	rRddlm}y|j|�}Wn|jk
r@YnX|j|dd��Wntk
rr|j|�YnXdS)zMRuns a callback with error handling.

        For use in subclasses.
        Nr)�gencSs|j�S)N)rX)�frrrrSjsz&IOLoop._run_callback.<locals>.<lambda>)rLrrrQZ
BadYieldErrorrWrT�handle_callback_exception)r$rj�retrrrrr�
_run_callbackUszIOLoop._run_callbackcCstjd|dd�dS)aUThis method is called whenever a callback run by the `IOLoop`
        throws an exception.

        By default simply logs the exception as an error.  Subclasses
        may override this method to customize reporting of exceptions.

        The exception itself is not passed explicitly, but is available
        in `sys.exc_info`.
        zException in callback %rT)rVN)r	�error)r$rjrrrrtns
z IOLoop.handle_callback_exceptioncCs*y|j�|fStk
r$||fSXdS)a�Returns an (fd, obj) pair from an ``fd`` parameter.

        We accept both raw file descriptors and file-like objects as
        input to `add_handler` and related methods.  When a file-like
        object is passed, we must retain the object itself so we can
        close it correctly when the `IOLoop` shuts down, but the
        poller interfaces favor file descriptors (they will accept
        file-like objects and call ``fileno()`` for you, but they
        always return the descriptor itself).

        This method is provided for use by `IOLoop` subclasses and should
        not generally be used by application code.

        .. versionadded:: 4.0
        N)�fileno�AttributeError)r$r9rrr�split_fdzszIOLoop.split_fdcCsJy0y|j�Wntk
r,tj|�YnXWntk
rDYnXdS)akUtility method to close an ``fd``.

        If ``fd`` is a file-like object, we close it directly; otherwise
        we use `os.close`.

        This method is provided for use by `IOLoop` subclasses (in
        implementations of ``IOLoop.close(all_fds=True)`` and should
        not generally be used by application code.

        .. versionadded:: 4.0
        N)r8ry�os�OSError)r$r9rrr�close_fd�szIOLoop.close_fdi@l)T)N)F)N)9rrr�__doc__Z_EPOLLINZ	_EPOLLPRIZ	_EPOLLOUTZ	_EPOLLERRZ	_EPOLLHUPZ_EPOLLRDHUPZ
_EPOLLONESHOTZ_EPOLLETZNONE�READZWRITE�ERROR�	threading�Lockr Zlocalr(�staticmethodr!r"r%r&r)r*r+�classmethodr-r3r5r8r<r=r>rArCrBrKrOrPrbr^r]rmrfr_r\rnrprWrvrtrzr}rrrrrGsd7
	
	
				
7"
	
rcs�eZdZdZd�fdd�	Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Z�ZS) �
PollIOLoopaBase class for IOLoops built around a select-like function.

    For concrete implementations, see `tornado.platform.epoll.EPollIOLoop`
    (Linux), `tornado.platform.kqueue.KQueueIOLoop` (BSD and Mac), or
    `tornado.platform.select.SelectIOLoop` (all platforms).
    Ncs�tt��jf|�|�_t�jd�r2t�jj��|p:tj�_i�_	i�_
g�_tj
��_g�_d�_d�_d�_d�_d�_d�_tj��_t��_�j�jj��fdd��j�dS)NrxrFcs
�jj�S)N)�_wakerZconsume)r9r;)r$rrrS�sz'PollIOLoop.initialize.<locals>.<lambda>)�superr�r5�_implrrrxr^�	time_func�	_handlers�_events�
_callbacksr�r��_callback_lock�	_timeouts�_cancellations�_running�_stopped�_closing�
_thread_identrE�	itertools�count�_timeout_counterrr�r<r)r$�implr�rl)�	__class__)r$rr5�s*


zPollIOLoop.initializeFc
Csr|j�d|_WdQRX|j|jj��|rNx |jj�D]\}}|j|�q8W|jj�|j	j�d|_
d|_dS)NT)r�r�r>r�rxr��valuesr}r8r�r�r�)r$r7r9r:rrrr8�s

zPollIOLoop.closecCs:|j|�\}}|tj|�f|j|<|jj|||jB�dS)N)rzrrqr�r��registerr�)r$r9r:r;�objrrrr<�szPollIOLoop.add_handlercCs&|j|�\}}|jj|||jB�dS)N)rzr�Zmodifyr�)r$r9r;r�rrrr=�szPollIOLoop.update_handlercCsb|j|�\}}|jj|d�|jj|d�y|jj|�Wn"tk
r\tjddd�YnXdS)NzError deleting fd from IOLoopT)rV)	rzr��popr�r�Z
unregisterrTr
�debug)r$r9r�rrrr>�szPollIOLoop.remove_handlercCsFttd�stjd�dS||_|dk	rBtjtj|dk	r:|ntj�dS)N�	setitimerzPset_blocking_signal_threshold requires a signal module with the setitimer method)rrIr
rwrE�SIGALRM�SIG_DFL)r$r?r@rrrrA�s

z(PollIOLoop.set_blocking_signal_thresholdc3Cs�|jrtd��|j�|jr&d|_dSttjdd�}|tj_tj	�|_
d|_d}ttd�r�t
jdkr�y*tj|jj��}|d
kr�tj|�d}Wntk
r�d}YnX�z̐x�|j�|j}g|_WdQRXg}|j�r�|j�}xb|j�rD|jdjdk�rtj|j�|jd8_q�|jdj|k�r@|jtj|j��q�Pq�W|jd	k�r�|jt|j�d?k�r�d|_d
d�|jD�|_tj|j�x|D]}|j|��q�Wx&|D]}|jdk	�r�|j|j��q�Wd}}}}|j�r�d}n2|j�r|jdj|j�}t dt!|t"��}nt"}|j�s(P|j#dk	�rDtj$tj%dd�y|j&j'|�}	Wn:t(k
�r�}
zt)|
�t*j+k�r|w�n�WYdd}
~
XnX|j#dk	�r�tj$tj%|j#d�|j,j-|	�x�|j,�rf|j,j.�\}}y|j/|\}
}||
|�Wnrt0t1fk
�r:}
z*t)|
�t*j2k�rn|j3|j/j4|��WYdd}
~
Xn(t(k
�r`|j3|j/j4|��YnX�q�Wd}
}q�WWdd|_|j#dk	�r�tj$tj%dd�|tj_|dk	�r�tj|�XdS)NzIOLoop is already runningFr!T�
set_wakeup_fd�posixrricSsg|]}|jdk	r|�qS)N)rj)�.0�xrrr�
<listcomp>9sz$PollIOLoop.start.<locals>.<listcomp>g���)5r�r4rOr�r'rr(r!�thread�	get_identr�rrIr{�namer�r�Zwrite_fileno�
ValueErrorr�r�r�r^rj�heapq�heappopr�ri�append�len�heapifyrv�max�min�
_POLL_TIMEOUTrEr��ITIMER_REALr�ZpollrTr
�errnoZEINTRr��update�popitemr�r|�IOErrorZEPIPErt�get)r$Zold_currentZ
old_wakeup_fdZ	callbacksZdue_timeoutsZnowrjraZpoll_timeoutZevent_pairs�er9r;Zfd_objZhandler_funcrrrrK�s�







"
zPollIOLoop.startcCsd|_d|_|jj�dS)NFT)r�r�r��wake)r$rrrrP�szPollIOLoop.stopcCs|j�S)N)r�)r$rrrr^�szPollIOLoop.timecOs2t|tjtj|�f|�|�|�}tj|j|�|S)N)�_Timeout�	functools�partialrrqr��heappushr�)r$rirjrkrlrarrrrf�szPollIOLoop.call_atcCsd|_|jd7_dS)Nr)rjr�)r$rarrrr_�szPollIOLoop.remove_timeoutcOs�tj�|jkrb|j�F|jr dS|j}|jjtjt	j
|�f|�|��|rV|jj�WdQRXn*|jrldS|jjtjt	j
|�f|�|��dS)N)
r�r�r�r�r�r�r�r�r�rrqr�r�)r$rjrkrlZ
list_emptyrrrr\�s


zPollIOLoop.add_callbackc
Os*tj��|j|f|�|�WdQRXdS)N)rror\)r$rjrkrlrrrrn�s
z#PollIOLoop.add_callback_from_signal)N)F)rrrr~r5r8r<r=r>rArKrPr^rfr_r\rn�
__classcell__rr)r�rr��s
	
	 r�c@s2eZdZdZdddgZdd�Zdd�Zd	d
�ZdS)r�z2An IOLoop timeout, a UNIX timestamp and a callbackrirj�
tiebreakercCs4t|tj�std|��||_||_t|j�|_dS)NzUnsupported deadline %r)	rcrdrerhrirj�nextr�r�)r$rirj�io_looprrr�__init__�s
z_Timeout.__init__cCs|j|jf|j|jfkS)N)rir�)r$�otherrrr�__lt__�s
z_Timeout.__lt__cCs|j|jf|j|jfkS)N)rir�)r$r�rrr�__le__�s
z_Timeout.__le__N)rrrr~�	__slots__r�r�r�rrrrr��s

r�c@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�PeriodicCallbackaSchedules the given callback to be called periodically.

    The callback is called every ``callback_time`` milliseconds.
    Note that the timeout is given in milliseconds, while most other
    time-related functions in Tornado use seconds.

    If the callback runs for longer than ``callback_time`` milliseconds,
    subsequent invocations will be skipped to get back on schedule.

    `start` must be called after the `PeriodicCallback` is created.

    .. versionchanged:: 4.1
       The ``io_loop`` argument is deprecated.
    NcCs:||_|dkrtd��||_|p&tj�|_d|_d|_dS)Nrz4Periodic callback must have a positive callback_timeF)rjr��
callback_timerr)r�r��_timeout)r$rjr�r�rrrr��szPeriodicCallback.__init__cCsd|_|jj�|_|j�dS)zStarts the timer.TN)r�r�r^�
_next_timeout�_schedule_next)r$rrrrK�szPeriodicCallback.startcCs(d|_|jdk	r$|jj|j�d|_dS)zStops the timer.FN)r�r�r�r_)r$rrrrPs
zPeriodicCallback.stopcCs|jS)zaReturn True if this `.PeriodicCallback` has been started.

        .. versionadded:: 4.1
        )r�)r$rrr�
is_runningszPeriodicCallback.is_runningcCsJ|js
dSz0y|j�Stk
r6|jj|j�YnXWd|j�XdS)N)r�rjrTr�rtr�)r$rrr�_runszPeriodicCallback._runcCsb|jr^|jj�}|j|krJ|jd}|jtj||j|�d|7_|jj|j|j�|_	dS)Ng@�@r)
r�r�r^r�r��mathZfloorr]r�r�)r$Zcurrent_timeZcallback_time_secrrrr�s


&zPeriodicCallback._schedule_next)N)
rrrr~r�rKrPr�r�r�rrrrr��s
	
r�)/r~Z
__future__rrrrrgr�r�r�r�rNrdr{r2rUr�r^rGr�Z
concurrentrr�logr	r
rDr�utilrr
rrI�ImportErrorr��_threadZ
platform.autorrr�rTrrr��objectr�r�rrrr�<module>sP
a&