本文整理汇总了Python中asyncore.poll2方法的典型用法代码示例。如果您正苦于以下问题:Python asyncore.poll2方法的具体用法?Python asyncore.poll2怎么用?Python asyncore.poll2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncore
的用法示例。
在下文中一共展示了asyncore.poll2方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loop
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll2 [as 别名]
def loop(timeout=0.001, use_poll=False, map=None, count=None):
"""Start asyncore and scheduler loop.
Use this as replacement of the original asyncore.loop() function.
"""
if use_poll and hasattr(asyncore.select, 'poll'):
poll_fun = asyncore.poll2
else:
poll_fun = asyncore.poll
if map is None:
map = asyncore.socket_map
if count is None:
while (map or _tasks):
poll_fun(timeout, map)
_scheduler()
else:
while (map or _tasks) and count > 0:
poll_fun(timeout, map)
_scheduler()
count -= 1
示例2: debugging_server
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll2 [as 别名]
def debugging_server(serv, serv_evt, client_evt):
serv_evt.set()
try:
if hasattr(select, 'poll'):
poll_fun = asyncore.poll2
else:
poll_fun = asyncore.poll
n = 1000
while asyncore.socket_map and n > 0:
poll_fun(0.01, asyncore.socket_map)
# when the client conversation is finished, it will
# set client_evt, and it's then ok to kill the server
if client_evt.is_set():
serv.close()
break
n -= 1
except socket.timeout:
pass
finally:
if not client_evt.is_set():
# allow some time for the client to read the result
time.sleep(0.5)
serv.close()
asyncore.close_all()
serv_evt.set()
示例3: serve_forever
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll2 [as 别名]
def serve_forever(cls, timeout=1.0, use_poll=False, count=None):
"""A wrap around asyncore.loop(); starts the asyncore polling
loop including running the scheduler.
The arguments are the same expected by original asyncore.loop()
function:
- (float) timeout: the timeout passed to select() or poll()
system calls expressed in seconds (default 1.0).
- (bool) use_poll: when True use poll() instead of select()
(default False).
- (int) count: how many times the polling loop gets called
before returning. If None loops forever (default None).
"""
if use_poll and hasattr(asyncore.select, 'poll'):
poll_fun = asyncore.poll2
else:
poll_fun = asyncore.poll
if count is None:
log("Starting FTP server")
try:
try:
while asyncore.socket_map or _scheduler._tasks:
poll_fun(timeout)
_scheduler()
except (KeyboardInterrupt, SystemExit, asyncore.ExitNow):
pass
finally:
log("Shutting down FTP server")
cls.close_all()
else:
while (asyncore.socket_map or _scheduler._tasks) and count > 0:
if asyncore.socket_map:
poll_fun(timeout)
if _scheduler._tasks:
_scheduler()
count -= 1