def __init__(self):
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa363862(v=vs.85).aspx
self._closed = True
self._iocp = _check(
kernel32.
CreateIoCompletionPort(INVALID_HANDLE_VALUE, ffi.NULL, 0, 0)
)
self._closed = False
self._iocp_queue = deque()
self._iocp_thread = None
self._overlapped_waiters = {}
self._completion_key_queues = {}
# Completion key 0 is reserved for regular IO events
self._completion_key_counter = itertools.count(1)
# {stdlib socket object: task}
# except that wakeup socket is mapped to None
self._socket_waiters = {"read": {}, "write": {}}
self._main_thread_waker = WakeupSocketpair()
wakeup_sock = self._main_thread_waker.wakeup_sock
self._socket_waiters["read"][wakeup_sock] = None
# This is necessary to allow control-C to interrupt select().
# https://github.com/python-trio/trio/issues/42
if threading.current_thread() == threading.main_thread():
fileno = self._main_thread_waker.write_sock.fileno()
self._old_signal_wakeup_fd = signal.set_wakeup_fd(fileno)
评论列表
文章目录