本文整理汇总了Python中select.POLLNVAL属性的典型用法代码示例。如果您正苦于以下问题:Python select.POLLNVAL属性的具体用法?Python select.POLLNVAL怎么用?Python select.POLLNVAL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类select
的用法示例。
在下文中一共展示了select.POLLNVAL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_events
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def _parse_events(self, events):
"""Parse ``events``.
``events`` is a list of events as returned by
:meth:`select.poll.poll()`.
Yield all parsed events.
"""
for fd, event_mask in events:
if self._has_event(event_mask, select.POLLNVAL):
raise IOError('File descriptor not open: {0!r}'.format(fd))
elif self._has_event(event_mask, select.POLLERR):
raise IOError('Error while polling fd: {0!r}'.format(fd))
if self._has_event(event_mask, select.POLLIN):
yield fd, 'r'
if self._has_event(event_mask, select.POLLOUT):
yield fd, 'w'
if self._has_event(event_mask, select.POLLHUP):
yield fd, 'h'
示例2: run
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def run(self):
#print(self.run, 'enter')
while True:
#print(self.run, 'cycle')
pollret = dict(self.pollobj.poll()).get(self.fileno, 0)
if pollret & POLLNVAL != 0:
break
if pollret & POLLIN == 0:
continue
try:
clientsock, addr = self.clicm.serversock.accept()
except Exception as why:
if isinstance(why, socket.error):
if why.errno == ECONNABORTED:
continue
elif why.errno == EBADF:
break
else:
raise
dump_exception('CLIConnectionManager: unhandled exception when accepting incoming connection')
break
#print(self.run, 'handle_accept')
ED2.callFromThread(self.clicm.handle_accept, clientsock, addr)
self.clicm = None
#print(self.run, 'exit')
示例3: read
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def read(self, size=1):
"""Read size bytes from the serial port. If a timeout is set it may
return less characters as requested. With no timeout it will block
until the requested number of bytes is read."""
if self.fd is None: raise portNotOpenError
read = bytearray()
poll = select.poll()
poll.register(self.fd, select.POLLIN|select.POLLERR|select.POLLHUP|select.POLLNVAL)
if size > 0:
while len(read) < size:
# print "\tread(): size",size, "have", len(read) #debug
# wait until device becomes ready to read (or something fails)
for fd, event in poll.poll(self._timeout*1000):
if event & (select.POLLERR|select.POLLHUP|select.POLLNVAL):
raise SerialException('device reports error (poll)')
# we don't care if it is select.POLLIN or timeout, that's
# handled below
buf = os.read(self.fd, size - len(read))
read.extend(buf)
if ((self._timeout is not None and self._timeout >= 0) or
(self._interCharTimeout is not None and self._interCharTimeout > 0)) and not buf:
break # early abort on timeout
return bytes(read)
示例4: readwrite
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def readwrite(obj, flags):
try:
if flags & select.POLLIN:
obj.handle_read_event()
if flags & select.POLLOUT:
obj.handle_write_event()
if flags & select.POLLPRI:
obj.handle_expt_event()
if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
obj.handle_close()
except OSError as e:
if e.args[0] not in _DISCONNECTED:
obj.handle_error()
else:
obj.handle_close()
except _reraised_exceptions:
raise
except:
obj.handle_error()
示例5: poll
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def poll(self, timeout = None):
events = self._poll.poll(timeout)
processed = []
for fd, evt in events:
mask = ""
if evt & (select_module.POLLIN | select_module.POLLPRI):
mask += "r"
if evt & select_module.POLLOUT:
mask += "w"
if evt & select_module.POLLERR:
mask += "e"
if evt & select_module.POLLHUP:
mask += "h"
if evt & select_module.POLLNVAL:
mask += "n"
processed.append((fd, mask))
return processed
示例6: poll
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def poll(self, timeout):
if timeout is not None:
# convert from seconds to milliseconds
timeout *= 1000
changes = self._poll.poll(timeout)
results = []
for fd, events in changes:
f = self._get_file_object(fd)
if events & (select.POLLIN | select.POLLPRI):
results.append((f, POLLER_EVENT_READ))
elif events & (select.POLLOUT):
results.append((f, POLLER_EVENT_WRITE))
elif events & (select.POLLHUP):
results.append((f, POLLER_EVENT_HUP))
elif events & (select.POLLERR | select.POLLNVAL):
results.append((f, POLLER_EVENT_ERROR))
return results
示例7: _ensure_pipes
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def _ensure_pipes(self):
"Ensure that the channel is capable of communicating."
if self.read_pipe is None or self.write_pipe is None:
# Accept any incoming connections.
endpoint, address = self.endpoint.accept()
self.read_pipe = endpoint.makefile("rb", 0)
self.write_pipe = endpoint.makefile("wb", 0)
# Monitor the write pipe for error conditions.
fileno = self.write_pipe.fileno()
self.poller.register(fileno, select.POLLOUT | select.POLLHUP | select.POLLNVAL | select.POLLERR)
示例8: _ensure_communication
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def _ensure_communication(self, timeout=None):
"Ensure that sending and receiving are possible."
while 1:
self._ensure_pipes()
fileno = self.write_pipe.fileno()
fds = self.poller.poll(timeout)
for fd, status in fds:
if fd != fileno:
continue
if status & (select.POLLHUP | select.POLLNVAL | select.POLLERR):
# Broken connection: discard it and start all over again.
self._reset_pipes()
break
else:
return
示例9: _poll
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def _poll(fds, timeout):
if timeout is not None:
timeout = int(timeout * 1000) # timeout is in milliseconds
fd_map = {}
pollster = select.poll()
for fd in fds:
pollster.register(fd, select.POLLIN)
if hasattr(fd, 'fileno'):
fd_map[fd.fileno()] = fd
else:
fd_map[fd] = fd
ls = []
for fd, event in pollster.poll(timeout):
if event & select.POLLNVAL: # pragma: no cover
raise ValueError('invalid file descriptor %i' % fd)
ls.append(fd_map[fd])
return ls
示例10: readwrite
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def readwrite(obj, flags):
try:
if flags & select.POLLIN:
obj.handle_read_event()
if flags & select.POLLOUT:
obj.handle_write_event()
if flags & select.POLLPRI:
obj.handle_expt_event()
if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
obj.handle_close()
except socket.error, e:
if e.args[0] not in _DISCONNECTED:
obj.handle_error()
else:
obj.handle_close()
示例11: poll2
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def poll2(timeout=0.0, map=None):
# Use the poll() support added to the select module in Python 2.0
if map is None:
map = socket_map
if timeout is not None:
# timeout is in milliseconds
timeout = int(timeout*1000)
pollster = select.poll()
if map:
for fd, obj in map.items():
flags = 0
if obj.readable():
flags |= select.POLLIN | select.POLLPRI
if obj.writable():
flags |= select.POLLOUT
if flags:
# Only check for exceptions if object was either readable
# or writable.
flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
pollster.register(fd, flags)
try:
r = pollster.poll(timeout)
except select.error, err:
if err.args[0] != EINTR:
raise
r = []
for fd, flags in r:
obj = map.get(fd)
if obj is None:
continue
readwrite(obj, flags)
示例12: poll2
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def poll2(timeout=0.0, map=None):
# Use the poll() support added to the select module in Python 2.0
if map is None:
map = socket_map
if timeout is not None:
# timeout is in milliseconds
timeout = int(timeout*1000)
pollster = select.poll()
if map:
for fd, obj in map.items():
flags = 0
if obj.readable():
flags |= select.POLLIN | select.POLLPRI
# accepting sockets should not be writable
if obj.writable() and not obj.accepting:
flags |= select.POLLOUT
if flags:
# Only check for exceptions if object was either readable
# or writable.
flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
pollster.register(fd, flags)
try:
r = pollster.poll(timeout)
except select.error, err:
if err.args[0] != EINTR:
raise
r = []
for fd, flags in r:
obj = map.get(fd)
if obj is None:
continue
readwrite(obj, flags)
示例13: read
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def read(self, size=1):
"""\
Read size bytes from the serial port. If a timeout is set it may
return less characters as requested. With no timeout it will block
until the requested number of bytes is read.
"""
if not self.is_open:
raise portNotOpenError
read = bytearray()
poll = select.poll()
poll.register(self.fd, select.POLLIN | select.POLLERR | select.POLLHUP | select.POLLNVAL)
if size > 0:
while len(read) < size:
# print "\tread(): size",size, "have", len(read) #debug
# wait until device becomes ready to read (or something fails)
for fd, event in poll.poll(self._timeout * 1000):
if event & (select.POLLERR | select.POLLHUP | select.POLLNVAL):
raise SerialException('device reports error (poll)')
# we don't care if it is select.POLLIN or timeout, that's
# handled below
buf = os.read(self.fd, size - len(read))
read.extend(buf)
if ((self._timeout is not None and self._timeout >= 0) or
(self._inter_byte_timeout is not None and self._inter_byte_timeout > 0)) and not buf:
break # early abort on timeout
return bytes(read)
示例14: _listen
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def _listen(self):
"""
Listen for new inbound connections and messages from existing
connections.
"""
self._socket.listen(1)
self._listening = True
self._pobj.register(
self._socket.fileno(),
select.POLLIN | select.POLLNVAL | select.POLLHUP,
)
closed = False
while (not closed) and self._listening:
events = self._pobj.poll(1.0)
for fdesc, event in events:
if fdesc == self._socket.fileno():
# Socket event received
if event in [select.POLLNVAL, select.POLLHUP]:
self.log_callback('"Close socket" event received.')
closed = True
break # out of 'for'
elif event == select.POLLIN:
self.log_callback('"New connection" event received.')
self._add_connection()
else:
raise Exception(
"Unexpected event {0} on fdesc {1}.".format(
event, fdesc
)
)
else:
# Connection event received
self._process_connection_event(fdesc, event)
self._remove_all_connections()
self._socket.shutdown(socket.SHUT_RDWR)
self._socket.close()
示例15: _add_connection
# 需要导入模块: import select [as 别名]
# 或者: from select import POLLNVAL [as 别名]
def _add_connection(self):
"""
Accept new inbound connection from socket.
"""
connection, _ = self._socket.accept()
conn_details = ConnectionDetails(connection)
self._conndetails_by_fd[connection.fileno()] = conn_details
self._pobj.register(
connection.fileno(),
select.POLLIN | select.POLLNVAL | select.POLLHUP,
)