本文整理汇总了Python中asyncore.poll方法的典型用法代码示例。如果您正苦于以下问题:Python asyncore.poll方法的具体用法?Python asyncore.poll怎么用?Python asyncore.poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncore
的用法示例。
在下文中一共展示了asyncore.poll方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handle_expt
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [as 别名]
def test_handle_expt(self):
# Make sure handle_expt is called on OOB data received.
# Note: this might fail on some platforms as OOB data is
# tenuously supported and rarely used.
if sys.platform == "darwin" and self.use_poll:
self.skipTest("poll may fail on macOS; see issue #28087")
class TestClient(BaseClient):
def handle_expt(self):
self.flag = True
class TestHandler(BaseTestHandler):
def __init__(self, conn):
BaseTestHandler.__init__(self, conn)
self.socket.send(chr(244), socket.MSG_OOB)
server = TCPServer(TestHandler)
client = TestClient(server.address)
self.loop_waiting_for_flag(client)
示例2: loop
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [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
示例3: test_handle_expt
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [as 别名]
def test_handle_expt(self):
# Make sure handle_expt is called on OOB data received.
# Note: this might fail on some platforms as OOB data is
# tenuously supported and rarely used.
if HAS_UNIX_SOCKETS and self.family == socket.AF_UNIX:
self.skipTest("Not applicable to AF_UNIX sockets.")
if sys.platform == "darwin" and self.use_poll:
self.skipTest("poll may fail on macOS; see issue #28087")
class TestClient(BaseClient):
def handle_expt(self):
self.socket.recv(1024, socket.MSG_OOB)
self.flag = True
class TestHandler(BaseTestHandler):
def __init__(self, conn):
BaseTestHandler.__init__(self, conn)
self.socket.send(bytes(chr(244), 'latin-1'), socket.MSG_OOB)
server = BaseServer(self.family, self.addr, TestHandler)
client = TestClient(self.family, server.address)
self.loop_waiting_for_flag(client)
示例4: InitConnection
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [as 别名]
def InitConnection(self):
self.reader = Lirc_Reader(
self.host,
self.port,
self,
self.onlyfirst,
self.addremote,
self.addrepeat,
self.ignoretime
)
# Send LIST commands to the server..
# In order to get remote-names and buttons in response
if self.attemptlist:
self.reader.sbuffer += "LIST\n"
# Have to wait a bit and force asyncore to poll to check for a response
time.sleep(0.05)
asyncore.poll()
self.checkListingTimer = threading.Timer(4, self.CheckListingResults)
self.checkListingTimer.start()
time.sleep(0.5)
asyncore.poll()
示例5: debugging_server
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [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()
示例6: test_readwriteexc
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [as 别名]
def test_readwriteexc(self):
# Check exception handling behavior of read, write and _exception
# check that ExitNow exceptions in the object handler method
# bubbles all the way up through asyncore read/write/_exception calls
tr1 = exitingdummy()
self.assertRaises(asyncore.ExitNow, asyncore.read, tr1)
self.assertRaises(asyncore.ExitNow, asyncore.write, tr1)
self.assertRaises(asyncore.ExitNow, asyncore._exception, tr1)
# check that an exception other than ExitNow in the object handler
# method causes the handle_error method to get called
tr2 = crashingdummy()
asyncore.read(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore.write(tr2)
self.assertEqual(tr2.error_handled, True)
tr2 = crashingdummy()
asyncore._exception(tr2)
self.assertEqual(tr2.error_handled, True)
# asyncore.readwrite uses constants in the select module that
# are not present in Windows systems (see this thread:
# http://mail.python.org/pipermail/python-list/2001-October/109973.html)
# These constants should be present as long as poll is available
示例7: test_send
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [as 别名]
def test_send(self):
evt = threading.Event()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(3)
port = test_support.bind_port(sock)
cap = StringIO()
args = (evt, cap, sock)
t = threading.Thread(target=capture_server, args=args)
t.start()
try:
# wait a little longer for the server to initialize (it sometimes
# refuses connections on slow machines without this wait)
time.sleep(0.2)
data = "Suppose there isn't a 16-ton weight?"
d = dispatcherwithsend_noread()
d.create_socket(socket.AF_INET, socket.SOCK_STREAM)
d.connect((HOST, port))
# give time for socket to connect
time.sleep(0.1)
d.send(data)
d.send(data)
d.send('\n')
n = 1000
while d.out_buffer and n > 0:
asyncore.poll()
n -= 1
evt.wait()
self.assertEqual(cap.getvalue(), data*2)
finally:
t.join()
示例8: serve_forever
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [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
示例9: test_send
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [as 别名]
def test_send(self):
evt = threading.Event()
sock = socket.socket()
sock.settimeout(3)
port = support.bind_port(sock)
cap = BytesIO()
args = (evt, cap, sock)
t = threading.Thread(target=capture_server, args=args)
t.start()
try:
# wait a little longer for the server to initialize (it sometimes
# refuses connections on slow machines without this wait)
time.sleep(0.2)
data = b"Suppose there isn't a 16-ton weight?"
d = dispatcherwithsend_noread()
d.create_socket()
d.connect((support.HOST, port))
# give time for socket to connect
time.sleep(0.1)
d.send(data)
d.send(data)
d.send(b'\n')
n = 1000
while d.out_buffer and n > 0:
asyncore.poll()
n -= 1
evt.wait()
self.assertEqual(cap.getvalue(), data*2)
finally:
t.join(timeout=TIMEOUT)
if t.is_alive():
self.fail("join() timed out")
示例10: signal_handler
# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import poll [as 别名]
def signal_handler(signal, frame):
global server
global must_exit
logging.error('Exiting...')
must_exit = True
del server
# Wrapper around the asyncore loop that lets us poll the in/out pipes every 1ms