本文整理汇总了Python中asyncio.Future.done方法的典型用法代码示例。如果您正苦于以下问题:Python Future.done方法的具体用法?Python Future.done怎么用?Python Future.done使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncio.Future
的用法示例。
在下文中一共展示了Future.done方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import done [as 别名]
class Tester:
def __init__(self):
self.end = Future()
def __call__(self, *args, **kwargs):
if not self.end.done():
self.end.set_result((args, kwargs))
示例2: _send_request
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import done [as 别名]
def _send_request(self, app_name, endpoint, entity, params):
packet = MessagePacket.request(self.name, self.version, app_name, _Service._REQ_PKT_STR, endpoint, params,
entity)
future = Future()
request_id = params['request_id']
self._pending_requests[request_id] = future
try:
self.tcp_bus.send(packet)
except ClientException as e:
if not future.done() and not future.cancelled():
ERROR = '101_Client not found'
exception = RequestException(ERROR)
exception.error = ERROR
future.set_exception(exception)
_Service.time_future(future, TCPServiceClient.REQUEST_TIMEOUT_SECS)
return future
示例3: _send_request
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import done [as 别名]
def _send_request(self, app_name, endpoint, entity, params, timeout):
packet = MessagePacket.request(self.name, self.version, app_name, _Service._REQ_PKT_STR, endpoint, params,
entity)
future = Future()
request_id = params['request_id']
self._pending_requests[request_id] = future
try:
self.tcp_bus.send(packet)
except ClientException:
if not future.done() and not future.cancelled():
error = 'Client not found'
exception = ClientException(error)
exception.error = error
future.set_exception(exception)
_Service.time_future(future, timeout)
return future
示例4: SubscriberThread
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import done [as 别名]
class SubscriberThread(threading.Thread):
def __init__(self, topic, id):
super().__init__(target=self)
self.subscriber = Subscriber(topic=topic, id=id)
self.future = Future()
def done(self):
return self.future.done()
def result(self):
return self.future.result()
def run(self):
try:
self.subscriber.open()
result = self.loop()
self.future.set_result(result)
except Exception as error:
self.future.set_exception(error)
finally:
self.subscriber.close()
def loop(self):
raise NotImplementedError()
示例5: WebSocketAdapterProtocol
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import done [as 别名]
class WebSocketAdapterProtocol(asyncio.Protocol):
"""
Adapter class for asyncio-based WebSocket client and server protocols.
"""
def connection_made(self, transport):
self.transport = transport
self.receive_queue = deque()
self._consume()
try:
peer = transport.get_extra_info('peername')
try:
# FIXME: tcp4 vs tcp6
self.peer = u"tcp:%s:%d" % (peer[0], peer[1])
except:
# e.g. Unix Domain sockets don't have host/port
self.peer = u"unix:{0}".format(peer)
except:
self.peer = u"?"
self._connectionMade()
def connection_lost(self, exc):
self._connectionLost(exc)
# according to asyncio docs, connection_lost(None) is called
# if something else called transport.close()
if exc is not None:
self.transport.close()
self.transport = None
def _consume(self):
self.waiter = Future(loop=self.factory.loop or txaio.config.loop)
def process(_):
while len(self.receive_queue):
data = self.receive_queue.popleft()
if self.transport:
self._dataReceived(data)
self._consume()
self.waiter.add_done_callback(process)
def data_received(self, data):
self.receive_queue.append(data)
if not self.waiter.done():
self.waiter.set_result(None)
# noinspection PyUnusedLocal
def _closeConnection(self, abort=False):
self.transport.close()
def _onOpen(self):
res = self.onOpen()
if yields(res):
ensure_future(res)
def _onMessageBegin(self, isBinary):
res = self.onMessageBegin(isBinary)
if yields(res):
ensure_future(res)
def _onMessageFrameBegin(self, length):
res = self.onMessageFrameBegin(length)
if yields(res):
ensure_future(res)
def _onMessageFrameData(self, payload):
res = self.onMessageFrameData(payload)
if yields(res):
ensure_future(res)
def _onMessageFrameEnd(self):
res = self.onMessageFrameEnd()
if yields(res):
ensure_future(res)
def _onMessageFrame(self, payload):
res = self.onMessageFrame(payload)
if yields(res):
ensure_future(res)
def _onMessageEnd(self):
res = self.onMessageEnd()
if yields(res):
ensure_future(res)
def _onMessage(self, payload, isBinary):
res = self.onMessage(payload, isBinary)
if yields(res):
ensure_future(res)
def _onPing(self, payload):
res = self.onPing(payload)
if yields(res):
ensure_future(res)
def _onPong(self, payload):
res = self.onPong(payload)
#.........这里部分代码省略.........
示例6: WebSocketAdapterProtocol
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import done [as 别名]
class WebSocketAdapterProtocol(asyncio.Protocol):
"""
Adapter class for asyncio-based WebSocket client and server protocols.
"""
def connection_made(self, transport):
self.transport = transport
self.receive_queue = deque()
self._consume()
try:
peer = transport.get_extra_info('peername')
try:
# FIXME: tcp4 vs tcp6
self.peer = "tcp:%s:%d" % (peer[0], peer[1])
except:
# e.g. Unix Domain sockets don't have host/port
self.peer = "unix:{0}".format(peer)
except:
self.peer = "?"
self._connectionMade()
def connection_lost(self, exc):
self._connectionLost(exc)
self.transport = None
def _consume(self):
self.waiter = Future()
def process(_):
while len(self.receive_queue):
data = self.receive_queue.popleft()
if self.transport:
self._dataReceived(data)
else:
print("WebSocketAdapterProtocol._consume: no transport")
self._consume()
self.waiter.add_done_callback(process)
def data_received(self, data):
self.receive_queue.append(data)
if not self.waiter.done():
self.waiter.set_result(None)
# noinspection PyUnusedLocal
def _closeConnection(self, abort=False):
self.transport.close()
def _onOpen(self):
res = self.onOpen()
if yields(res):
asyncio.async(res)
def _onMessageBegin(self, isBinary):
res = self.onMessageBegin(isBinary)
if yields(res):
asyncio.async(res)
def _onMessageFrameBegin(self, length):
res = self.onMessageFrameBegin(length)
if yields(res):
asyncio.async(res)
def _onMessageFrameData(self, payload):
res = self.onMessageFrameData(payload)
if yields(res):
asyncio.async(res)
def _onMessageFrameEnd(self):
res = self.onMessageFrameEnd()
if yields(res):
asyncio.async(res)
def _onMessageFrame(self, payload):
res = self.onMessageFrame(payload)
if yields(res):
asyncio.async(res)
def _onMessageEnd(self):
res = self.onMessageEnd()
if yields(res):
asyncio.async(res)
def _onMessage(self, payload, isBinary):
res = self.onMessage(payload, isBinary)
if yields(res):
asyncio.async(res)
def _onPing(self, payload):
res = self.onPing(payload)
if yields(res):
asyncio.async(res)
def _onPong(self, payload):
res = self.onPong(payload)
if yields(res):
asyncio.async(res)
#.........这里部分代码省略.........
示例7: WebSocketAdapterProtocol
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import done [as 别名]
class WebSocketAdapterProtocol(asyncio.Protocol):
"""
Adapter class for asyncio-based WebSocket client and server protocols.
"""
def connection_made(self, transport):
self.transport = transport
self.receive_queue = deque()
self._consume()
try:
self.peer = peer2str(transport.get_extra_info('peername'))
except:
self.peer = u"?"
self._connectionMade()
def connection_lost(self, exc):
self._connectionLost(exc)
# according to asyncio docs, connection_lost(None) is called
# if something else called transport.close()
if exc is not None:
self.transport.close()
self.transport = None
def _consume(self):
self.waiter = Future(loop=self.factory.loop or txaio.config.loop)
def process(_):
while len(self.receive_queue):
data = self.receive_queue.popleft()
if self.transport:
self._dataReceived(data)
self._consume()
self.waiter.add_done_callback(process)
def data_received(self, data):
self.receive_queue.append(data)
if not self.waiter.done():
self.waiter.set_result(None)
def _closeConnection(self, abort=False):
if abort and hasattr(self.transport, 'abort'):
self.transport.abort()
else:
self.transport.close()
def _onOpen(self):
res = self.onOpen()
if yields(res):
ensure_future(res)
def _onMessageBegin(self, isBinary):
res = self.onMessageBegin(isBinary)
if yields(res):
ensure_future(res)
def _onMessageFrameBegin(self, length):
res = self.onMessageFrameBegin(length)
if yields(res):
ensure_future(res)
def _onMessageFrameData(self, payload):
res = self.onMessageFrameData(payload)
if yields(res):
ensure_future(res)
def _onMessageFrameEnd(self):
res = self.onMessageFrameEnd()
if yields(res):
ensure_future(res)
def _onMessageFrame(self, payload):
res = self.onMessageFrame(payload)
if yields(res):
ensure_future(res)
def _onMessageEnd(self):
res = self.onMessageEnd()
if yields(res):
ensure_future(res)
def _onMessage(self, payload, isBinary):
res = self.onMessage(payload, isBinary)
if yields(res):
ensure_future(res)
def _onPing(self, payload):
res = self.onPing(payload)
if yields(res):
ensure_future(res)
def _onPong(self, payload):
res = self.onPong(payload)
if yields(res):
ensure_future(res)
def _onClose(self, wasClean, code, reason):
#.........这里部分代码省略.........