【发布时间】:2015-01-25 00:25:23
【问题描述】:
我最近读到 BSD kqueue 可以接受各种事件,而不仅仅是文件描述符。但对于 Linux 用户来说,它看起来像这样:
(来自socketserver python stdlib)
#self being passed to select is a listening socket
try:
while not self.__shutdown_request:
# XXX: Consider using another file descriptor or
# connecting to the socket to wake this up instead of
# polling. Polling reduces our responsiveness to a
# shutdown request and wastes cpu at all other times.
r, w, e = _eintr_retry(select.select, [self], [], [],
poll_interval)
if self in r:
self._handle_request_noblock()
self.service_actions()
是否有一些聪明的方法来检查threading.Event() 和select 或poll 还是必须连接第二个套接字来监听关闭事件的不可避免的情况?
编辑:我要寻找的是这样的:
select.select([self, clever_wrapper(self.__shutdown_request)], [], [])
【问题讨论】:
标签: python linux multithreading sockets