本文整理汇总了Python中txaio.resolve函数的典型用法代码示例。如果您正苦于以下问题:Python resolve函数的具体用法?Python resolve怎么用?Python resolve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resolve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_future_explicit_loop
def test_create_future_explicit_loop(framework):
"""
process events on alternate loop= for create_future later
"""
pytest.importorskip('asyncio')
if txaio.using_twisted:
pytest.skip()
import asyncio
alt_loop = asyncio.new_event_loop()
txa = txaio.with_config(loop=alt_loop)
f = txa.create_future()
results = []
f.add_done_callback(lambda r: results.append(r.result()))
assert results == []
txaio.resolve(f, 'some result')
# run_once() runs the txaio.config.loop so we shouldn't get any
# results until we spin alt_loop
assert results == []
run_once()
assert results == []
with replace_loop(alt_loop):
run_once()
assert results == ['some result']
示例2: on_leave
def on_leave(session, details):
self.log.info(
"session leaving '{details.reason}'",
details=details,
)
if self._entry and not txaio.is_called(done):
txaio.resolve(done, None)
示例3: process
def process(signature_raw):
# convert the raw signature into a hex encode value (unicode string)
signature_hex = binascii.b2a_hex(signature_raw).decode('ascii')
# we return the concatenation of the signature and the message signed (96 bytes)
data_hex = binascii.b2a_hex(data).decode('ascii')
sig = signature_hex + data_hex
txaio.resolve(d2, sig)
示例4: connectionLost
def connectionLost(self, reason):
self.log.debug("WampRawSocketProtocol: connection lost: reason = '{reason}'", reason=reason)
txaio.resolve(self.is_closed, self)
try:
wasClean = isinstance(reason.value, ConnectionDone)
self._session.onClose(wasClean)
except Exception as e:
# silently ignore exceptions raised here ..
self.log.warn("WampRawSocketProtocol: ApplicationSession.onClose raised ({err})", err=e)
self._session = None
示例5: methodReturnReceived
def methodReturnReceived(self, mret):
"""
Called when a method return message is received
"""
d, timeout = self._pendingCalls.get(mret.reply_serial, (None,None))
if timeout:
timeout.cancel()
if d:
del self._pendingCalls[ mret.reply_serial ]
txaio.resolve(d, mret)
示例6: error
def error(fail):
self._delay_f = None
if self._stopping:
# might be better to add framework-specific checks in
# subclasses to see if this is CancelledError (for
# Twisted) and whatever asyncio does .. but tracking
# if we're in the shutdown path is fine too
txaio.resolve(self._done_f, None)
else:
self.log.info("Internal error {msg}", msg=txaio.failure_message(fail))
self.log.debug("{tb}", tb=txaio.failure_format_traceback(fail))
txaio.reject(self._done_f, fail)
示例7: _notify_some
def _notify_some(receivers):
# we do a first pass over the proposed chunk of receivers
# because not all of them will have a transport, and if this
# will be the last chunk of receivers we need to figure out
# which event is last...
receivers_this_chunk = []
for receiver in receivers[:chunk_size]:
if receiver._session_id and receiver._transport:
receivers_this_chunk.append(receiver)
else:
vanished_receivers.append(receiver)
receivers = receivers[chunk_size:]
# XXX note there's still going to be some edge-cases here .. if
# we are NOT the last chunk, but all the next chunk's receivers
# (could be only 1 in that chunk!) vanish before we run our next
# batch, then a "last" event will never go out ...
# we now actually do the deliveries, but now we know which
# receiver is the last one
if receivers or not self._router.is_traced:
# NOT the last chunk (or we're not traced so don't care)
for receiver in receivers_this_chunk:
# send out WAMP msg to peer
self._router.send(receiver, msg)
if self._event_store or storing_event:
self._event_store.store_event_history(publication, subscription.id, receiver)
else:
# last chunk, so last receiver gets the different message
for receiver in receivers_this_chunk[:-1]:
self._router.send(receiver, msg)
if self._event_store or storing_event:
self._event_store.store_event_history(publication, subscription.id, receiver)
# FIXME: I don't get the following comment and code path. when, how? and what to
# do about event store? => storing_event
#
# we might have zero valid receivers
if receivers_this_chunk:
self._router.send(receivers_this_chunk[-1], last_msg)
# FIXME: => storing_event
if receivers:
# still more to do ..
return txaio.call_later(0, _notify_some, receivers)
else:
# all done! resolve all_d, which represents all receivers
# to a single subscription matching the event
txaio.resolve(all_d, None)
示例8: test_callback
def test_callback(framework):
f = txaio.create_future()
results = []
def cb(f):
results.append(f)
txaio.add_callbacks(f, cb, None)
txaio.resolve(f, "it worked")
run_once()
assert len(results) == 1
assert results[0] == "it worked"
示例9: on_leave
def on_leave(session, details):
self.log.info(
"session leaving '{details.reason}'",
details=details,
)
if not txaio.is_called(done):
if details.reason in [u"wamp.close.normal"]:
txaio.resolve(done, None)
else:
f = txaio.create_failure(
ApplicationError(details.reason)
)
txaio.reject(done, f)
示例10: on_disconnect
def on_disconnect(session, was_clean):
self.log.debug(
"session on_disconnect: was_clean={was_clean}",
was_clean=was_clean,
)
if not txaio.is_called(done):
if not was_clean:
self.log.warn(
u"Session disconnected uncleanly"
)
# eg the session has left the realm, and the transport was properly
# shut down. successfully finish the connection
txaio.resolve(done, None)
示例11: on_leave
def on_leave(session, details):
self.log.info(
"session leaving '{details.reason}'",
details=details,
)
if not txaio.is_called(done):
if details.reason in [u"wamp.error.no_auth_method"]:
txaio.resolve(done, txaio.create_failure(
ApplicationError(
u"wamp.error.no_auth_method"
)
))
else:
txaio.resolve(done, None)
示例12: stop
def stop(self):
self._stopping = True
if self._session and self._session.is_attached():
return self._session.leave()
elif self._delay_f:
# This cancel request will actually call the "error" callback of
# the _delay_f future. Nothing to worry about.
return txaio.as_future(txaio.cancel, self._delay_f)
# if (for some reason -- should we log warning here to figure
# out if this can evern happen?) we've not fired _done_f, we
# do that now (causing our "main" to exit, and thus react() to
# quit)
if not txaio.is_called(self._done_f):
txaio.resolve(self._done_f, None)
return txaio.create_future_success(None)
示例13: test_chained_callback
def test_chained_callback(framework):
"""
Chain two callbacks where the first one alters the value.
"""
calls = []
def callback0(arg):
calls.append(arg)
return arg + " pray I do not alter it futher"
def callback1(arg):
calls.append(arg)
f = txaio.create_future()
txaio.add_callbacks(f, callback0, None)
txaio.add_callbacks(f, callback1, None)
txaio.resolve(f, "the deal")
run_once()
assert len(calls) == 2
assert calls[0] == "the deal"
assert calls[1] == "the deal pray I do not alter it futher"
示例14: onJoin
def onJoin(self, details):
txaio.resolve(d, None)
示例15: cb
from __future__ import print_function
import txaio
def cb(value):
print("Callback:", value)
return value # should always return input arg
def eb(fail):
# fail will implement txaio.IFailedPromise
print("Errback:", fail)
# fail.printTraceback()
return fail # should always return input arg
f0 = txaio.create_future()
f1 = txaio.create_future()
txaio.add_callbacks(f0, cb, eb)
txaio.add_callbacks(f1, cb, eb)
# ...
txaio.reject(f0, RuntimeError("it failed"))
# or can just "txaio.reject(f0)" if inside an except: block
txaio.resolve(f1, "The answer is: 42")
if txaio.using_asyncio:
# for twisted, we don't need to enter the event-loop for this
# simple example (since all results are already available), but
# you'd simply use reactor.run()/.stop() or task.react() as normal
import asyncio
asyncio.get_event_loop().run_until_complete(f1)