本文整理匯總了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