Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3....
File: selectors.py
"""Selectors module.
[0] Fix | Delete
[1] Fix | Delete
This module allows high-level and efficient I/O multiplexing, built upon the
[2] Fix | Delete
`select` module primitives.
[3] Fix | Delete
"""
[4] Fix | Delete
[5] Fix | Delete
[6] Fix | Delete
from abc import ABCMeta, abstractmethod
[7] Fix | Delete
from collections import namedtuple, Mapping
[8] Fix | Delete
import math
[9] Fix | Delete
import select
[10] Fix | Delete
import sys
[11] Fix | Delete
[12] Fix | Delete
[13] Fix | Delete
# generic events, that must be mapped to implementation-specific ones
[14] Fix | Delete
EVENT_READ = (1 << 0)
[15] Fix | Delete
EVENT_WRITE = (1 << 1)
[16] Fix | Delete
[17] Fix | Delete
[18] Fix | Delete
def _fileobj_to_fd(fileobj):
[19] Fix | Delete
"""Return a file descriptor from a file object.
[20] Fix | Delete
[21] Fix | Delete
Parameters:
[22] Fix | Delete
fileobj -- file object or file descriptor
[23] Fix | Delete
[24] Fix | Delete
Returns:
[25] Fix | Delete
corresponding file descriptor
[26] Fix | Delete
[27] Fix | Delete
Raises:
[28] Fix | Delete
ValueError if the object is invalid
[29] Fix | Delete
"""
[30] Fix | Delete
if isinstance(fileobj, int):
[31] Fix | Delete
fd = fileobj
[32] Fix | Delete
else:
[33] Fix | Delete
try:
[34] Fix | Delete
fd = int(fileobj.fileno())
[35] Fix | Delete
except (AttributeError, TypeError, ValueError):
[36] Fix | Delete
raise ValueError("Invalid file object: "
[37] Fix | Delete
"{!r}".format(fileobj)) from None
[38] Fix | Delete
if fd < 0:
[39] Fix | Delete
raise ValueError("Invalid file descriptor: {}".format(fd))
[40] Fix | Delete
return fd
[41] Fix | Delete
[42] Fix | Delete
[43] Fix | Delete
SelectorKey = namedtuple('SelectorKey', ['fileobj', 'fd', 'events', 'data'])
[44] Fix | Delete
[45] Fix | Delete
SelectorKey.__doc__ = """SelectorKey(fileobj, fd, events, data)
[46] Fix | Delete
[47] Fix | Delete
Object used to associate a file object to its backing
[48] Fix | Delete
file descriptor, selected event mask, and attached data.
[49] Fix | Delete
"""
[50] Fix | Delete
if sys.version_info >= (3, 5):
[51] Fix | Delete
SelectorKey.fileobj.__doc__ = 'File object registered.'
[52] Fix | Delete
SelectorKey.fd.__doc__ = 'Underlying file descriptor.'
[53] Fix | Delete
SelectorKey.events.__doc__ = 'Events that must be waited for on this file object.'
[54] Fix | Delete
SelectorKey.data.__doc__ = ('''Optional opaque data associated to this file object.
[55] Fix | Delete
For example, this could be used to store a per-client session ID.''')
[56] Fix | Delete
[57] Fix | Delete
class _SelectorMapping(Mapping):
[58] Fix | Delete
"""Mapping of file objects to selector keys."""
[59] Fix | Delete
[60] Fix | Delete
def __init__(self, selector):
[61] Fix | Delete
self._selector = selector
[62] Fix | Delete
[63] Fix | Delete
def __len__(self):
[64] Fix | Delete
return len(self._selector._fd_to_key)
[65] Fix | Delete
[66] Fix | Delete
def __getitem__(self, fileobj):
[67] Fix | Delete
try:
[68] Fix | Delete
fd = self._selector._fileobj_lookup(fileobj)
[69] Fix | Delete
return self._selector._fd_to_key[fd]
[70] Fix | Delete
except KeyError:
[71] Fix | Delete
raise KeyError("{!r} is not registered".format(fileobj)) from None
[72] Fix | Delete
[73] Fix | Delete
def __iter__(self):
[74] Fix | Delete
return iter(self._selector._fd_to_key)
[75] Fix | Delete
[76] Fix | Delete
[77] Fix | Delete
class BaseSelector(metaclass=ABCMeta):
[78] Fix | Delete
"""Selector abstract base class.
[79] Fix | Delete
[80] Fix | Delete
A selector supports registering file objects to be monitored for specific
[81] Fix | Delete
I/O events.
[82] Fix | Delete
[83] Fix | Delete
A file object is a file descriptor or any object with a `fileno()` method.
[84] Fix | Delete
An arbitrary object can be attached to the file object, which can be used
[85] Fix | Delete
for example to store context information, a callback, etc.
[86] Fix | Delete
[87] Fix | Delete
A selector can use various implementations (select(), poll(), epoll()...)
[88] Fix | Delete
depending on the platform. The default `Selector` class uses the most
[89] Fix | Delete
efficient implementation on the current platform.
[90] Fix | Delete
"""
[91] Fix | Delete
[92] Fix | Delete
@abstractmethod
[93] Fix | Delete
def register(self, fileobj, events, data=None):
[94] Fix | Delete
"""Register a file object.
[95] Fix | Delete
[96] Fix | Delete
Parameters:
[97] Fix | Delete
fileobj -- file object or file descriptor
[98] Fix | Delete
events -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE)
[99] Fix | Delete
data -- attached data
[100] Fix | Delete
[101] Fix | Delete
Returns:
[102] Fix | Delete
SelectorKey instance
[103] Fix | Delete
[104] Fix | Delete
Raises:
[105] Fix | Delete
ValueError if events is invalid
[106] Fix | Delete
KeyError if fileobj is already registered
[107] Fix | Delete
OSError if fileobj is closed or otherwise is unacceptable to
[108] Fix | Delete
the underlying system call (if a system call is made)
[109] Fix | Delete
[110] Fix | Delete
Note:
[111] Fix | Delete
OSError may or may not be raised
[112] Fix | Delete
"""
[113] Fix | Delete
raise NotImplementedError
[114] Fix | Delete
[115] Fix | Delete
@abstractmethod
[116] Fix | Delete
def unregister(self, fileobj):
[117] Fix | Delete
"""Unregister a file object.
[118] Fix | Delete
[119] Fix | Delete
Parameters:
[120] Fix | Delete
fileobj -- file object or file descriptor
[121] Fix | Delete
[122] Fix | Delete
Returns:
[123] Fix | Delete
SelectorKey instance
[124] Fix | Delete
[125] Fix | Delete
Raises:
[126] Fix | Delete
KeyError if fileobj is not registered
[127] Fix | Delete
[128] Fix | Delete
Note:
[129] Fix | Delete
If fileobj is registered but has since been closed this does
[130] Fix | Delete
*not* raise OSError (even if the wrapped syscall does)
[131] Fix | Delete
"""
[132] Fix | Delete
raise NotImplementedError
[133] Fix | Delete
[134] Fix | Delete
def modify(self, fileobj, events, data=None):
[135] Fix | Delete
"""Change a registered file object monitored events or attached data.
[136] Fix | Delete
[137] Fix | Delete
Parameters:
[138] Fix | Delete
fileobj -- file object or file descriptor
[139] Fix | Delete
events -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE)
[140] Fix | Delete
data -- attached data
[141] Fix | Delete
[142] Fix | Delete
Returns:
[143] Fix | Delete
SelectorKey instance
[144] Fix | Delete
[145] Fix | Delete
Raises:
[146] Fix | Delete
Anything that unregister() or register() raises
[147] Fix | Delete
"""
[148] Fix | Delete
self.unregister(fileobj)
[149] Fix | Delete
return self.register(fileobj, events, data)
[150] Fix | Delete
[151] Fix | Delete
@abstractmethod
[152] Fix | Delete
def select(self, timeout=None):
[153] Fix | Delete
"""Perform the actual selection, until some monitored file objects are
[154] Fix | Delete
ready or a timeout expires.
[155] Fix | Delete
[156] Fix | Delete
Parameters:
[157] Fix | Delete
timeout -- if timeout > 0, this specifies the maximum wait time, in
[158] Fix | Delete
seconds
[159] Fix | Delete
if timeout <= 0, the select() call won't block, and will
[160] Fix | Delete
report the currently ready file objects
[161] Fix | Delete
if timeout is None, select() will block until a monitored
[162] Fix | Delete
file object becomes ready
[163] Fix | Delete
[164] Fix | Delete
Returns:
[165] Fix | Delete
list of (key, events) for ready file objects
[166] Fix | Delete
`events` is a bitwise mask of EVENT_READ|EVENT_WRITE
[167] Fix | Delete
"""
[168] Fix | Delete
raise NotImplementedError
[169] Fix | Delete
[170] Fix | Delete
def close(self):
[171] Fix | Delete
"""Close the selector.
[172] Fix | Delete
[173] Fix | Delete
This must be called to make sure that any underlying resource is freed.
[174] Fix | Delete
"""
[175] Fix | Delete
pass
[176] Fix | Delete
[177] Fix | Delete
def get_key(self, fileobj):
[178] Fix | Delete
"""Return the key associated to a registered file object.
[179] Fix | Delete
[180] Fix | Delete
Returns:
[181] Fix | Delete
SelectorKey for this file object
[182] Fix | Delete
"""
[183] Fix | Delete
mapping = self.get_map()
[184] Fix | Delete
if mapping is None:
[185] Fix | Delete
raise RuntimeError('Selector is closed')
[186] Fix | Delete
try:
[187] Fix | Delete
return mapping[fileobj]
[188] Fix | Delete
except KeyError:
[189] Fix | Delete
raise KeyError("{!r} is not registered".format(fileobj)) from None
[190] Fix | Delete
[191] Fix | Delete
@abstractmethod
[192] Fix | Delete
def get_map(self):
[193] Fix | Delete
"""Return a mapping of file objects to selector keys."""
[194] Fix | Delete
raise NotImplementedError
[195] Fix | Delete
[196] Fix | Delete
def __enter__(self):
[197] Fix | Delete
return self
[198] Fix | Delete
[199] Fix | Delete
def __exit__(self, *args):
[200] Fix | Delete
self.close()
[201] Fix | Delete
[202] Fix | Delete
[203] Fix | Delete
class _BaseSelectorImpl(BaseSelector):
[204] Fix | Delete
"""Base selector implementation."""
[205] Fix | Delete
[206] Fix | Delete
def __init__(self):
[207] Fix | Delete
# this maps file descriptors to keys
[208] Fix | Delete
self._fd_to_key = {}
[209] Fix | Delete
# read-only mapping returned by get_map()
[210] Fix | Delete
self._map = _SelectorMapping(self)
[211] Fix | Delete
[212] Fix | Delete
def _fileobj_lookup(self, fileobj):
[213] Fix | Delete
"""Return a file descriptor from a file object.
[214] Fix | Delete
[215] Fix | Delete
This wraps _fileobj_to_fd() to do an exhaustive search in case
[216] Fix | Delete
the object is invalid but we still have it in our map. This
[217] Fix | Delete
is used by unregister() so we can unregister an object that
[218] Fix | Delete
was previously registered even if it is closed. It is also
[219] Fix | Delete
used by _SelectorMapping.
[220] Fix | Delete
"""
[221] Fix | Delete
try:
[222] Fix | Delete
return _fileobj_to_fd(fileobj)
[223] Fix | Delete
except ValueError:
[224] Fix | Delete
# Do an exhaustive search.
[225] Fix | Delete
for key in self._fd_to_key.values():
[226] Fix | Delete
if key.fileobj is fileobj:
[227] Fix | Delete
return key.fd
[228] Fix | Delete
# Raise ValueError after all.
[229] Fix | Delete
raise
[230] Fix | Delete
[231] Fix | Delete
def register(self, fileobj, events, data=None):
[232] Fix | Delete
if (not events) or (events & ~(EVENT_READ | EVENT_WRITE)):
[233] Fix | Delete
raise ValueError("Invalid events: {!r}".format(events))
[234] Fix | Delete
[235] Fix | Delete
key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
[236] Fix | Delete
[237] Fix | Delete
if key.fd in self._fd_to_key:
[238] Fix | Delete
raise KeyError("{!r} (FD {}) is already registered"
[239] Fix | Delete
.format(fileobj, key.fd))
[240] Fix | Delete
[241] Fix | Delete
self._fd_to_key[key.fd] = key
[242] Fix | Delete
return key
[243] Fix | Delete
[244] Fix | Delete
def unregister(self, fileobj):
[245] Fix | Delete
try:
[246] Fix | Delete
key = self._fd_to_key.pop(self._fileobj_lookup(fileobj))
[247] Fix | Delete
except KeyError:
[248] Fix | Delete
raise KeyError("{!r} is not registered".format(fileobj)) from None
[249] Fix | Delete
return key
[250] Fix | Delete
[251] Fix | Delete
def modify(self, fileobj, events, data=None):
[252] Fix | Delete
# TODO: Subclasses can probably optimize this even further.
[253] Fix | Delete
try:
[254] Fix | Delete
key = self._fd_to_key[self._fileobj_lookup(fileobj)]
[255] Fix | Delete
except KeyError:
[256] Fix | Delete
raise KeyError("{!r} is not registered".format(fileobj)) from None
[257] Fix | Delete
if events != key.events:
[258] Fix | Delete
self.unregister(fileobj)
[259] Fix | Delete
key = self.register(fileobj, events, data)
[260] Fix | Delete
elif data != key.data:
[261] Fix | Delete
# Use a shortcut to update the data.
[262] Fix | Delete
key = key._replace(data=data)
[263] Fix | Delete
self._fd_to_key[key.fd] = key
[264] Fix | Delete
return key
[265] Fix | Delete
[266] Fix | Delete
def close(self):
[267] Fix | Delete
self._fd_to_key.clear()
[268] Fix | Delete
self._map = None
[269] Fix | Delete
[270] Fix | Delete
def get_map(self):
[271] Fix | Delete
return self._map
[272] Fix | Delete
[273] Fix | Delete
def _key_from_fd(self, fd):
[274] Fix | Delete
"""Return the key associated to a given file descriptor.
[275] Fix | Delete
[276] Fix | Delete
Parameters:
[277] Fix | Delete
fd -- file descriptor
[278] Fix | Delete
[279] Fix | Delete
Returns:
[280] Fix | Delete
corresponding key, or None if not found
[281] Fix | Delete
"""
[282] Fix | Delete
try:
[283] Fix | Delete
return self._fd_to_key[fd]
[284] Fix | Delete
except KeyError:
[285] Fix | Delete
return None
[286] Fix | Delete
[287] Fix | Delete
[288] Fix | Delete
class SelectSelector(_BaseSelectorImpl):
[289] Fix | Delete
"""Select-based selector."""
[290] Fix | Delete
[291] Fix | Delete
def __init__(self):
[292] Fix | Delete
super().__init__()
[293] Fix | Delete
self._readers = set()
[294] Fix | Delete
self._writers = set()
[295] Fix | Delete
[296] Fix | Delete
def register(self, fileobj, events, data=None):
[297] Fix | Delete
key = super().register(fileobj, events, data)
[298] Fix | Delete
if events & EVENT_READ:
[299] Fix | Delete
self._readers.add(key.fd)
[300] Fix | Delete
if events & EVENT_WRITE:
[301] Fix | Delete
self._writers.add(key.fd)
[302] Fix | Delete
return key
[303] Fix | Delete
[304] Fix | Delete
def unregister(self, fileobj):
[305] Fix | Delete
key = super().unregister(fileobj)
[306] Fix | Delete
self._readers.discard(key.fd)
[307] Fix | Delete
self._writers.discard(key.fd)
[308] Fix | Delete
return key
[309] Fix | Delete
[310] Fix | Delete
if sys.platform == 'win32':
[311] Fix | Delete
def _select(self, r, w, _, timeout=None):
[312] Fix | Delete
r, w, x = select.select(r, w, w, timeout)
[313] Fix | Delete
return r, w + x, []
[314] Fix | Delete
else:
[315] Fix | Delete
_select = select.select
[316] Fix | Delete
[317] Fix | Delete
def select(self, timeout=None):
[318] Fix | Delete
timeout = None if timeout is None else max(timeout, 0)
[319] Fix | Delete
ready = []
[320] Fix | Delete
try:
[321] Fix | Delete
r, w, _ = self._select(self._readers, self._writers, [], timeout)
[322] Fix | Delete
except InterruptedError:
[323] Fix | Delete
return ready
[324] Fix | Delete
r = set(r)
[325] Fix | Delete
w = set(w)
[326] Fix | Delete
for fd in r | w:
[327] Fix | Delete
events = 0
[328] Fix | Delete
if fd in r:
[329] Fix | Delete
events |= EVENT_READ
[330] Fix | Delete
if fd in w:
[331] Fix | Delete
events |= EVENT_WRITE
[332] Fix | Delete
[333] Fix | Delete
key = self._key_from_fd(fd)
[334] Fix | Delete
if key:
[335] Fix | Delete
ready.append((key, events & key.events))
[336] Fix | Delete
return ready
[337] Fix | Delete
[338] Fix | Delete
[339] Fix | Delete
if hasattr(select, 'poll'):
[340] Fix | Delete
[341] Fix | Delete
class PollSelector(_BaseSelectorImpl):
[342] Fix | Delete
"""Poll-based selector."""
[343] Fix | Delete
[344] Fix | Delete
def __init__(self):
[345] Fix | Delete
super().__init__()
[346] Fix | Delete
self._poll = select.poll()
[347] Fix | Delete
[348] Fix | Delete
def register(self, fileobj, events, data=None):
[349] Fix | Delete
key = super().register(fileobj, events, data)
[350] Fix | Delete
poll_events = 0
[351] Fix | Delete
if events & EVENT_READ:
[352] Fix | Delete
poll_events |= select.POLLIN
[353] Fix | Delete
if events & EVENT_WRITE:
[354] Fix | Delete
poll_events |= select.POLLOUT
[355] Fix | Delete
self._poll.register(key.fd, poll_events)
[356] Fix | Delete
return key
[357] Fix | Delete
[358] Fix | Delete
def unregister(self, fileobj):
[359] Fix | Delete
key = super().unregister(fileobj)
[360] Fix | Delete
self._poll.unregister(key.fd)
[361] Fix | Delete
return key
[362] Fix | Delete
[363] Fix | Delete
def select(self, timeout=None):
[364] Fix | Delete
if timeout is None:
[365] Fix | Delete
timeout = None
[366] Fix | Delete
elif timeout <= 0:
[367] Fix | Delete
timeout = 0
[368] Fix | Delete
else:
[369] Fix | Delete
# poll() has a resolution of 1 millisecond, round away from
[370] Fix | Delete
# zero to wait *at least* timeout seconds.
[371] Fix | Delete
timeout = math.ceil(timeout * 1e3)
[372] Fix | Delete
ready = []
[373] Fix | Delete
try:
[374] Fix | Delete
fd_event_list = self._poll.poll(timeout)
[375] Fix | Delete
except InterruptedError:
[376] Fix | Delete
return ready
[377] Fix | Delete
for fd, event in fd_event_list:
[378] Fix | Delete
events = 0
[379] Fix | Delete
if event & ~select.POLLIN:
[380] Fix | Delete
events |= EVENT_WRITE
[381] Fix | Delete
if event & ~select.POLLOUT:
[382] Fix | Delete
events |= EVENT_READ
[383] Fix | Delete
[384] Fix | Delete
key = self._key_from_fd(fd)
[385] Fix | Delete
if key:
[386] Fix | Delete
ready.append((key, events & key.events))
[387] Fix | Delete
return ready
[388] Fix | Delete
[389] Fix | Delete
[390] Fix | Delete
if hasattr(select, 'epoll'):
[391] Fix | Delete
[392] Fix | Delete
class EpollSelector(_BaseSelectorImpl):
[393] Fix | Delete
"""Epoll-based selector."""
[394] Fix | Delete
[395] Fix | Delete
def __init__(self):
[396] Fix | Delete
super().__init__()
[397] Fix | Delete
self._epoll = select.epoll()
[398] Fix | Delete
[399] Fix | Delete
def fileno(self):
[400] Fix | Delete
return self._epoll.fileno()
[401] Fix | Delete
[402] Fix | Delete
def register(self, fileobj, events, data=None):
[403] Fix | Delete
key = super().register(fileobj, events, data)
[404] Fix | Delete
epoll_events = 0
[405] Fix | Delete
if events & EVENT_READ:
[406] Fix | Delete
epoll_events |= select.EPOLLIN
[407] Fix | Delete
if events & EVENT_WRITE:
[408] Fix | Delete
epoll_events |= select.EPOLLOUT
[409] Fix | Delete
try:
[410] Fix | Delete
self._epoll.register(key.fd, epoll_events)
[411] Fix | Delete
except BaseException:
[412] Fix | Delete
super().unregister(fileobj)
[413] Fix | Delete
raise
[414] Fix | Delete
return key
[415] Fix | Delete
[416] Fix | Delete
def unregister(self, fileobj):
[417] Fix | Delete
key = super().unregister(fileobj)
[418] Fix | Delete
try:
[419] Fix | Delete
self._epoll.unregister(key.fd)
[420] Fix | Delete
except OSError:
[421] Fix | Delete
# This can happen if the FD was closed since it
[422] Fix | Delete
# was registered.
[423] Fix | Delete
pass
[424] Fix | Delete
return key
[425] Fix | Delete
[426] Fix | Delete
def select(self, timeout=None):
[427] Fix | Delete
if timeout is None:
[428] Fix | Delete
timeout = -1
[429] Fix | Delete
elif timeout <= 0:
[430] Fix | Delete
timeout = 0
[431] Fix | Delete
else:
[432] Fix | Delete
# epoll_wait() has a resolution of 1 millisecond, round away
[433] Fix | Delete
# from zero to wait *at least* timeout seconds.
[434] Fix | Delete
timeout = math.ceil(timeout * 1e3) * 1e-3
[435] Fix | Delete
[436] Fix | Delete
# epoll_wait() expects `maxevents` to be greater than zero;
[437] Fix | Delete
# we want to make sure that `select()` can be called when no
[438] Fix | Delete
# FD is registered.
[439] Fix | Delete
max_ev = max(len(self._fd_to_key), 1)
[440] Fix | Delete
[441] Fix | Delete
ready = []
[442] Fix | Delete
try:
[443] Fix | Delete
fd_event_list = self._epoll.poll(timeout, max_ev)
[444] Fix | Delete
except InterruptedError:
[445] Fix | Delete
return ready
[446] Fix | Delete
for fd, event in fd_event_list:
[447] Fix | Delete
events = 0
[448] Fix | Delete
if event & ~select.EPOLLIN:
[449] Fix | Delete
events |= EVENT_WRITE
[450] Fix | Delete
if event & ~select.EPOLLOUT:
[451] Fix | Delete
events |= EVENT_READ
[452] Fix | Delete
[453] Fix | Delete
key = self._key_from_fd(fd)
[454] Fix | Delete
if key:
[455] Fix | Delete
ready.append((key, events & key.events))
[456] Fix | Delete
return ready
[457] Fix | Delete
[458] Fix | Delete
def close(self):
[459] Fix | Delete
self._epoll.close()
[460] Fix | Delete
super().close()
[461] Fix | Delete
[462] Fix | Delete
[463] Fix | Delete
if hasattr(select, 'devpoll'):
[464] Fix | Delete
[465] Fix | Delete
class DevpollSelector(_BaseSelectorImpl):
[466] Fix | Delete
"""Solaris /dev/poll selector."""
[467] Fix | Delete
[468] Fix | Delete
def __init__(self):
[469] Fix | Delete
super().__init__()
[470] Fix | Delete
self._devpoll = select.devpoll()
[471] Fix | Delete
[472] Fix | Delete
def fileno(self):
[473] Fix | Delete
return self._devpoll.fileno()
[474] Fix | Delete
[475] Fix | Delete
def register(self, fileobj, events, data=None):
[476] Fix | Delete
key = super().register(fileobj, events, data)
[477] Fix | Delete
poll_events = 0
[478] Fix | Delete
if events & EVENT_READ:
[479] Fix | Delete
poll_events |= select.POLLIN
[480] Fix | Delete
if events & EVENT_WRITE:
[481] Fix | Delete
poll_events |= select.POLLOUT
[482] Fix | Delete
self._devpoll.register(key.fd, poll_events)
[483] Fix | Delete
return key
[484] Fix | Delete
[485] Fix | Delete
def unregister(self, fileobj):
[486] Fix | Delete
key = super().unregister(fileobj)
[487] Fix | Delete
self._devpoll.unregister(key.fd)
[488] Fix | Delete
return key
[489] Fix | Delete
[490] Fix | Delete
def select(self, timeout=None):
[491] Fix | Delete
if timeout is None:
[492] Fix | Delete
timeout = None
[493] Fix | Delete
elif timeout <= 0:
[494] Fix | Delete
timeout = 0
[495] Fix | Delete
else:
[496] Fix | Delete
# devpoll() has a resolution of 1 millisecond, round away from
[497] Fix | Delete
# zero to wait *at least* timeout seconds.
[498] Fix | Delete
timeout = math.ceil(timeout * 1e3)
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function