本文整理匯總了Python中select.EPOLLET屬性的典型用法代碼示例。如果您正苦於以下問題:Python select.EPOLLET屬性的具體用法?Python select.EPOLLET怎麽用?Python select.EPOLLET使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類select
的用法示例。
在下文中一共展示了select.EPOLLET屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _poll_queue_event
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def _poll_queue_event(self, events):
"""
EPoll event callback
"""
for fd, event in events:
if not (event & (select.EPOLLPRI | select.EPOLLET)):
continue
try:
values = self._allocated_pins.itervalues()
except AttributeError:
values = self._allocated_pins.values()
for pin in values:
if pin.fileno() == fd:
pin.changed(pin.read())
示例2: bind
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def bind(self):
"""
bind the ip:port
"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._set_sock_params(sock)
sock.bind((self._bind_ip, self._bind_port))
self._set_sock_nonblocking(sock)
log.info(
'bind port info:(ip:%s, port:%s)' % (
self._bind_ip, self._bind_port
)
)
self._epoll.register(
sock.fileno(),
select.EPOLLIN | select.EPOLLET | select.EPOLLOUT | select.EPOLLERR
)
self._bind_sock = sock
示例3: _handle_new_conn
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def _handle_new_conn(self, newsock, peer):
self._set_sock_params(newsock)
self._set_sock_nonblocking(newsock)
context = sockcontext.CConnContext()
context.set_sock(newsock)
context.set_conn_man(self)
context.set_peerinfo(peer)
self._epoll.register(
newsock.fileno(), select.EPOLLIN | select.EPOLLET | select.EPOLLERR
)
self._rwlock.acquire_writelock()
self._fileno2context[newsock.fileno()] = context
self._peer2context[peer] = context
self._context2fileno_peer[context] = (newsock.fileno(), peer)
self._rwlock.release_writelock()
log.info('a new connection: {0}'.format(peer))
示例4: _run
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def _run(self):
while self._running:
events = self._poll.poll(EPOLL_TIMEOUT)
for fd, event in events:
if not (event & (select.EPOLLPRI | select.EPOLLET)):
continue
self.changed(self.read())
示例5: __init__
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def __init__(self, options = select.EPOLLET, maxwait = 60):
'''
Constructor
'''
self.epoll = select.epoll()
self.defaultoption = options
self.mask = select.EPOLLIN|select.EPOLLPRI|select.EPOLLOUT|\
select.EPOLLRDNORM|select.EPOLLRDBAND|select.EPOLLWRNORM|\
select.EPOLLWRBAND|select.EPOLLONESHOT|select.EPOLLET
self.socketCounter = 0
self.maxwait = maxwait
self.daemons = set()
self.shouldraise = False
示例6: _poll_queue_register_pin
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def _poll_queue_register_pin(self, pin):
''' Pin responds to fileno(), so it's pollable. '''
self._poll_queue.register(pin, (select.EPOLLPRI | select.EPOLLET))
示例7: register
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [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))
示例8: __init__
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def __init__(self, server_address):
"""初始化服務器TCP套接字"""
self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.tcp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.tcp_socket.bind(server_address)
self.tcp_socket.listen(128)
self.tcp_socket.setblocking(False) # 將套接字設置為非阻塞模式
self.epoll = select.epoll() # 創建一個epoll對象
self.epoll.register(self.tcp_socket.fileno(), select.EPOLLIN | select.EPOLLET) # 將服務套接字注冊
self.connections = {}
self.addresses = {}
示例9: serve_forever
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def serve_forever(self):
"""永久運行監聽接收連接"""
while True:
epoll_list = self.epoll.poll()
for fd, events in epoll_list:
if fd == self.tcp_socket.fileno():
new_client_socket, new_client_address = self.tcp_socket.accept()
print(new_client_address, '向服務器發起了請求')
self.connections[new_client_socket.fileno()] = new_client_socket # 存入客戶連接事件文件描述符
self.addresses[new_client_socket.fileno()] = new_client_address
# 向epoll中則側新socket的可讀事件
self.epoll.register(new_client_socket.fileno(), select.EPOLLIN | select.EPOLLET)
elif events == select.EPOLLIN:
self.handlerequest(fd)
示例10: serve_forever
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def serve_forever(self):
"""永久運行監聽接收連接"""
while True:
epoll_list = self.epoll.poll()
for fd, events in epoll_list:
if fd == self.tcp_socket.fileno():
new_client_socket, new_client_address = self.tcp_socket.accept()
print(new_client_address, '向服務器發起了請求')
self.connections[new_client_socket.fileno()] = new_client_socket # 存入客戶連接事件文件描述符
self.addresses[new_client_socket.fileno()] = new_client_address
# 向epoll中則側新socket的可讀事件
self.epoll.register(new_client_socket.fileno(), select.EPOLLIN | select.EPOLLET)
elif events == select.EPOLLIN:
td = threading.Thread(target=self.handlerequest, args=(fd,))
td.start()
示例11: _epoll_write_params
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def _epoll_write_params(cls):
return (select.EPOLLET | select.EPOLLOUT | select.EPOLLERR)
示例12: _epoll_read_params
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def _epoll_read_params(cls):
return (select.EPOLLET | select.EPOLLIN | select.EPOLLERR)
示例13: _finish_read_callback
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def _finish_read_callback(self, succ, result):
context = result
if context.is_detroying():
# destroy the context and socket
context.release_readlock()
try:
self.cleanup_error_context(context)
except KeyError:
pass
else:
self._epoll.modify(
context.get_sock().fileno(), select.EPOLLIN | select.EPOLLET
)
context.release_readlock()
示例14: run
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def run(self):
poller = select.epoll()
poller.register(self.fd, self.event_mask | select.EPOLLET)
while self.running:
try:
events = poller.poll(timeout=1)
if events and self.callback is not None:
self.callback()
except OSError as exc:
# poller.poll() will raise an IOError because of the
# interrupted system call when suspending the machine.
logger.debug(f"Ignored IO error: {exc}")
示例15: test_control_and_wait
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLET [as 別名]
def test_control_and_wait(self):
client, server = self._connected_pair()
ep = select.epoll(16)
ep.register(server.fileno(),
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
ep.register(client.fileno(),
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
now = time.time()
events = ep.poll(1, 4)
then = time.time()
self.assertFalse(then - now > 0.1, then - now)
events.sort()
expected = [(client.fileno(), select.EPOLLOUT),
(server.fileno(), select.EPOLLOUT)]
expected.sort()
self.assertEqual(events, expected)
events = ep.poll(timeout=2.1, maxevents=4)
self.assertFalse(events)
client.send("Hello!")
server.send("world!!!")
now = time.time()
events = ep.poll(1, 4)
then = time.time()
self.assertFalse(then - now > 0.01)
events.sort()
expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT),
(server.fileno(), select.EPOLLIN | select.EPOLLOUT)]
expected.sort()
self.assertEqual(events, expected)
ep.unregister(client.fileno())
ep.modify(server.fileno(), select.EPOLLOUT)
now = time.time()
events = ep.poll(1, 4)
then = time.time()
self.assertFalse(then - now > 0.01)
expected = [(server.fileno(), select.EPOLLOUT)]
self.assertEqual(events, expected)