File: //lib64/python3.6/site-packages/zmq/eventloop/minitornado/__pycache__/ioloop.cpython-36.pyc
3
VS�_�� � @ s� d Z ddlmZmZmZmZ ddlZddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlmZmZ ddlmZmZ ddlmZ ddlmZmZmZ yddl Z W n e!k
r� dZ Y nX yddl"Z"W n e!k
�r ddl#Z"Y nX dd l$m%Z%m&Z& d
Z'G dd� de(�Z)G d
d� de�Z*G dd� de*�Z+G dd� de,�Z-G dd� 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 e Zd ZdS )�TimeoutErrorN)�__name__�
__module__�__qualname__� r r �/usr/lib64/python3.6/ioloop.pyr C s r c @ s� e Zd ZdZdZdZdZdZdZdZ dRZ
dSZd
ZeZ
eZeeB Zej� 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 � � r c
C s4 t td�s.tj� t td�s$t� t_W dQ R X tjS )a1 Returns 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_lockr r r r r �instance� s
zIOLoop.instancec C s
t td�S )z8Returns true if the singleton instance has been created.r )r r r r r r �initialized� s zIOLoop.initializedc C s t j� 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)r r"