本文整理汇总了Python中asyncio.Future.result方法的典型用法代码示例。如果您正苦于以下问题:Python Future.result方法的具体用法?Python Future.result怎么用?Python Future.result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asyncio.Future
的用法示例。
在下文中一共展示了Future.result方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doreqcb
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import result [as 别名]
def doreqcb(self, jobh: asyncio.Future):
fures = jobh.result()
res = fures[2]
req = fures[1]
reqid = fures[0]
# qDebug(str(res.status_code) + ', ' + str(res.headers))
self._res_map[reqid] = [req, res]
self._req_map.pop(reqid)
self.reqFinished.emit(reqid)
return
示例2: _inner
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import result [as 别名]
def _inner(fut: asyncio.Future):
result = fut.result() # type: Response
# Get the H2State for this request.
state = self.streams[stream_id] # type: H2State
# Get the app iterator.
it = result(environ, state.start_response)
headers = state.get_response_headers()
# Send the headers.
self.conn.send_headers(stream_id, headers, end_stream=False)
# Place all the data from the app iterator on the queue.
for i in it:
self.stream_data[stream_id].put_nowait(i)
# Add the sentinel value.
self.stream_data[stream_id].put_nowait(REQUEST_FINISHED)
示例3: SubscriberThread
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import result [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()
示例4: ClientProtocolMixin
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import result [as 别名]
class ClientProtocolMixin(Protocol):
"""
To use, inherit also from CyClientBase
You cannot inherit from it here to avoid two classes with predefined structure
inheriting and resulting in an error
"""
ACK_TIMEOUT_SECONDS = 1.0
ACK_TIMEOUT = 'ACK_TIMEOUT'
MISSED_MESSAGES_BEFORE_REREGISTRATION = 2
def __init__(self, verbose, dump, ticks_per_second, csv_writer_factory=None):
Protocol.__init__(self)
self._ticks_per_second = ticks_per_second
self.last_samples_received = None
self.cylib = EmotoolCylib(
parent=self, verbose=verbose, dump=dump,
csv_writer_factory=csv_writer_factory)
self.futures = Futures()
self.reset_ack()
self.connection_made_future = self.futures.add_future()
self._reset_task = None
self.start_check_progress()
def set_future_result(self, future, result):
self.futures.set_future_result(future, result)
def connection_made(self, transport):
self.transport = transport
self.cylib.parser.set_transport(transport)
self.set_future_result(self.connection_made_future, self)
def connection_lost(self, exc):
# generally, what do we want to do at this point? it could mean USB was unplugged, actually has to be? if client stops
# this wouldn't happen - we wouldn't notice at this level. So quit?
#self._debug_log("serial connection_lost")
pass
def exit_gracefully(self):
self.futures.cancel_all()
def send_message(self, msg_type, **kw):
self.cylib.parser.send_message(msg_type, **kw)
self.ack = self.futures.add_future(timeout=self.ACK_TIMEOUT_SECONDS, timeout_result=self.ACK_TIMEOUT)
def reset_ack(self):
self.ack = Future()
self.ack.set_result(True)
async def await_ack(self):
try:
await self.ack
except Exception as e:
import pdb; pdb.set_trace()
# XXX sometimes result is not available. Probably as a result of an ack
# being set to a new one. Treat it as no timeout.
try:
result = self.ack.result()
except:
result = None
is_timeout = result == self.ACK_TIMEOUT
self.reset_ack()
if is_timeout:
print("timeout {}".format(repr(self.futures._futures)))
raise AckTimeout()
async def send_set_variables(self, variables):
await self.send_sampler_clear()
self.cylib.sampler.clear()
for d in variables:
logger.info("Sending 'Register variable': {}".format(repr(d)))
await self._send_sampler_register_variable(
phase_ticks=d['phase_ticks'],
period_ticks=d['period_ticks'],
address=d['address'],
size=d['size']
)
self.cylib.sampler.register_variables(variables)
self._variables = variables
async def send_sampler_clear(self):
await self.send_and_ack(SamplerClear)
async def _send_sampler_register_variable(self, phase_ticks, period_ticks, address, size):
await self.send_and_ack(SamplerRegisterVariable,
phase_ticks=phase_ticks, period_ticks=period_ticks, address=address, size=size)
async def send_sampler_clear(self):
await self.send_and_ack(SamplerClear)
async def send_sampler_start(self):
await self.send_and_ack(SamplerStart)
self.cylib.sampler.on_started()
async def send_sampler_stop(self):
await self.send_and_ack(SamplerStop)
self.cylib.sampler.on_stopped()
def start_check_progress(self):
if self._reset_task is not None:
return
#.........这里部分代码省略.........
示例5: setter
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import result [as 别名]
def setter(f: asyncio.Future):
wrapper.set_result(f.result())
示例6: cb
# 需要导入模块: from asyncio import Future [as 别名]
# 或者: from asyncio.Future import result [as 别名]
def cb(future: asyncio.Future):
res = future.result()
if res.success:
f(res).relay_result(wrapper)
else:
wrapper.cancel()