本文整理汇总了Python中select.EPOLLHUP属性的典型用法代码示例。如果您正苦于以下问题:Python select.EPOLLHUP属性的具体用法?Python select.EPOLLHUP怎么用?Python select.EPOLLHUP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类select
的用法示例。
在下文中一共展示了select.EPOLLHUP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def run(self):
arcuslog(self, 'epoll start')
while True:
events = self.epoll.poll(2)
if self.node_allocator.shutdown == True:
arcuslog(self, 'epoll out')
return
for fileno, event in events:
if event & select.EPOLLIN:
node = self.sock_node_map[fileno]
node.do_op()
if event & select.EPOLLHUP:
print('EPOLL HUP')
epoll.unregister(fileno)
node = self.sock_node_map[fileno]
node.disconnect()
del self.sock_node_map[fileno]
示例2: handle_fd_mask
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def handle_fd_mask(self, fd, mask):
if fd == self._poll_bell.r:
assert mask & select.EPOLLIN
self._poll_bell.read(BELL_READ) # flush the pipe
else:
# socket might have been already discarded by the Link
# so this pass might be skipped
if fd not in self._sock_by_fd:
return
sock = self._sock_by_fd[fd]
if mask & (select.EPOLLERR | select.EPOLLHUP):
self.handle_sock_err(sock)
else:
if sock in self._in_ssl_handshake:
if self.ssl_handshake(sock) == SSL_HANDSHAKE_DONE:
# connection is ready for user IO
self.on_connect(sock.conn_id)
else:
self.handle_sock_io(fd, sock, mask)
##########################################################
示例3: register
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def register(self, sock, events, callback, *args, **kwargs):
ev = select.EPOLLERR | select.EPOLLHUP
need_modify = False
if sock.fileno() in self.fd2socks:
need_modify = True
if events & EV_READ:
ev |= select.EPOLLIN
if events & EV_WRITE:
ev |= select.EPOLLOUT
if need_modify:
self.epoll.modify(sock.fileno(), ev)
else:
try:
self.epoll.register(sock.fileno(), ev)
except (IOError, OSError):
return False
else:
self.fd2socks[sock.fileno()] = sock
return super(Epoll, self).register(sock, events, callback, *args, **kwargs)
示例4: perform
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def perform(self):
ret = []
for fd, event in self.epoll.poll():
if event & select.EPOLLHUP:
if DEBUG: DEBUG.info('downloader died')
raise KeyboardInterrupt
assert event & select.EPOLLIN
done = self.running[fd].perform()
if not done: continue
assert len(done) == 1
ret.extend(done)
# dl finished, move it to the cache
host = urlparse.urlsplit(done[0][0].url).netloc
if host in self.cache: self.cache[host].abort()
self.epoll.unregister(fd)
self.cache[host] = self.running.pop(fd)
return ret
示例5: receiveMsg_Start_Websocket
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def receiveMsg_Start_Websocket(self, m, sender):
if self.started: # already started
return
self.config = m
self.started = True
self.running = True
# open the connection
websocket.enableTrace(False)
self.ws = websocket.create_connection(m.ws_addr)
log.info("Websocket Connected")
# set up the socket monitoring
self.epoll = select.epoll()
mask = select.EPOLLIN | select.EPOLLHUP | select.EPOLLERR
self.epoll.register(self.ws.sock.fileno(), mask)
# subscribe to the feed
self.ws.send(m.start_msg)
# start checking for data
self.send(self.myAddress, WakeupMessage(None))
示例6: run
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def run(self):
arcuslog(self, 'epoll start')
while True:
events = self.epoll.poll(2)
if self.node_allocator.shutdown == True:
arcuslog(self, 'epoll out')
return
for fileno, event in events:
if event & select.EPOLLIN:
node = self.sock_node_map[fileno]
node.do_op()
if event & select.EPOLLHUP:
print('EPOLL HUP')
self.epoll.unregister(fileno)
node = self.sock_node_map[fileno]
node.disconnect()
del self.sock_node_map[fileno]
示例7: register
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def register(self, key, f):
BasePoller.register(self, key, f)
self.epoll.register(f.fileno(), select.EPOLLIN | select.EPOLLHUP |
select.EPOLLOUT)
self.fd_to_object[f.fileno()] = f
示例8: poll
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def poll(self, timeout=None):
if timeout is None:
timeout = -1
rv = []
for fd, event in self.epoll.poll(timeout):
obj = self.fd_to_object[fd]
if event & select.EPOLLIN:
rv.append((obj, 'read'))
if event & select.EPOLLOUT:
rv.append((obj, 'write'))
if event & select.EPOLLHUP:
rv.append((obj, 'close'))
return rv
示例9: __init__
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def __init__(self, pipe):
if isinstance(pipe, int):
fd = self._fd = pipe
pipe = os.fromfd(pipe)
else: fd = self._fd = pipe.fileno()
self._poll_in, self._poll_out = epoll(), epoll()
self._poll_in.register(fd, EPOLLIN | EPOLLERR | EPOLLHUP)
self._poll_out.register(fd, EPOLLOUT | EPOLLERR | EPOLLHUP)
self.close = pipe.close
self.reads = pipe.read
self.writes = pipe.write
示例10: read
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def read(self, bs=-1, to=-1, state=False): # read until timeout
if to < 0: # use regular sync I/O
buff = self.reads(bs)
if state: return (buff, Size) if len(buff) == bs else (buff, End) # "Size" might mean "Size | End" here
else: return buff
try:
flags = fcntl.fcntl(self._fd, fcntl.F_GETFL)
fcntl.fcntl(self._fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
deadline = time() + to
buff = buffer('')
while bs:
try: fd, event = self._poll_in.poll(to, 1)[0] # get first event, fd should be eq self._fd
except IndexError:
if state: state = Time
break
if event != EPOLLHUP: # some data or error present
ext = self.reads(min(bs, self.bs_max) if bs > 0 else self.bs_default) # min() for G+ reads
buff += ext
if event & EPOLLHUP: # socket is closed on the other end
if state: state = End
break
to = deadline - time()
if to < 0:
if state: state = Time
break
bs -= len(ext)
else: state = Size # got bs bytes
finally:
try: fcntl.fcntl(self._fd, fcntl.F_SETFL, flags) # restore blocking state
except: pass # in case there was an error, caused by wrong fd/pipe (not to raise another one)
return buff if not state else (buff, state)
示例11: write
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def write(self, buff, to=-1, state=False): # mostly similar (in reverse) to read
if to < 0:
bs = self.writes(buff)
if state: return (bs, Size) if len(buff) == bs else (bs, End) # "Size" might mean "Size | End" here
else: return bs
try:
flags = fcntl.fcntl(self._fd, fcntl.F_GETFL)
fcntl.fcntl(self._fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
bs = 0
deadline = time() + to
while buff:
try: fd, event = self._poll_out.poll(to, 1)[0]
except IndexError:
if state: state = Time
break
if event != EPOLLHUP:
ext = os.write(fd, buff)
bs += ext
if event & EPOLLHUP:
if state: state = End
break
to = deadline - time()
if to < 0:
if state: state = Time
break
buff = buffer(buff, ext)
finally:
try: fcntl.fcntl(self._fd, fcntl.F_SETFL, flags)
except: pass
return bs if not state else (bs, state)
示例12: doPoll
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def doPoll(self, block):
readyList = self.__poller.poll(-1 if block else 0)
for (fd, eventMask) in readyList:
readReady = ((eventMask & select.EPOLLIN) != 0)
writeReady = ((eventMask & select.EPOLLOUT) != 0)
errorReady = ((eventMask &
(select.EPOLLERR | select.EPOLLHUP)) != 0)
self.handleEventForFD(fd = fd,
readReady = readReady,
writeReady = writeReady,
errorReady = errorReady)
示例13: register
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def register(self, fd, *masks):
masks = [self.from_[x] for x in masks] + [
select.EPOLLET, select.EPOLLERR, select.EPOLLHUP]
self.q.register(fd, reduce(operator.or_, masks, 0))
示例14: poll
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def poll(self, timeout=-1):
events = self.q.poll(timeout=timeout)
ret = []
for fd, event in events:
for mask in self.to_:
if event & mask:
ret.append((fd, self.to_[mask]))
if event & (select.EPOLLERR | select.EPOLLHUP):
ret.append((fd, POLLERR))
return ret
示例15: _run_command
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLHUP [as 别名]
def _run_command(cmd, clear_streamed_output):
"""Calls the shell command, forwarding input received on the stdin_socket."""
locale_encoding = locale.getpreferredencoding()
if locale_encoding != _ENCODING:
raise NotImplementedError(
'A UTF-8 locale is required. Got {}'.format(locale_encoding))
parent_pty, child_pty = pty.openpty()
_configure_term_settings(child_pty)
epoll = select.epoll()
epoll.register(
parent_pty,
(select.EPOLLIN | select.EPOLLOUT | select.EPOLLHUP | select.EPOLLERR))
try:
temporary_clearer = _tags.temporary if clear_streamed_output else _no_op
with temporary_clearer(), _display_stdin_widget(
delay_millis=500) as update_stdin_widget:
# TODO(b/115531839): Ensure that subprocesses are terminated upon
# interrupt.
p = subprocess.Popen(
cmd,
shell=True,
executable='/bin/bash',
stdout=child_pty,
stdin=child_pty,
stderr=child_pty,
close_fds=True)
# The child PTY is only needed by the spawned process.
os.close(child_pty)
return _monitor_process(parent_pty, epoll, p, cmd, update_stdin_widget)
finally:
epoll.close()
os.close(parent_pty)