本文整理汇总了Python中twisted.internet.task.LoopingCall方法的典型用法代码示例。如果您正苦于以下问题:Python task.LoopingCall方法的具体用法?Python task.LoopingCall怎么用?Python task.LoopingCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.task
的用法示例。
在下文中一共展示了task.LoopingCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_telemetry
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def configure_telemetry(update):
global telemetry_looping_call
hostConfig = update.cache_get('hostConfig')
enabled = datastruct.getValue(hostConfig, 'telemetry.enabled', False)
interval = datastruct.getValue(hostConfig, 'telemetry.interval', 60)
# Cancel the old looping call.
if telemetry_looping_call is not None:
telemetry_looping_call.stop()
telemetry_looping_call = None
if enabled and interval > 0:
telemetry_looping_call = LoopingCall(reporting.sendTelemetryReport)
telemetry_looping_call.start(interval, now=False)
示例2: __init__
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def __init__(self, penguin):
self.penguin = penguin
self.logger = logging.getLogger(TIMELINE_LOGGER)
super(Refresh, self).__init__()
self.logger.info("Penguin ASync-Refresh service initialized : Penguin - {}".format(self.penguin['nickname']))
self.RefreshManagerLoop = LoopingCall(self._refresh)
self.firstTimeCall = True
self.CacheInitializedDefer = Deferred()
self.cache = PenguinObject()
self.penguin.penguin.data = self.cache # for easier access
self.cacheHandlers = PenguinObject()
self.logger.info("Penguin ASync-Refresh Loop started, every {}(s) : Penguin - {}".format
(self.REFRESH_INTERVAL, self.penguin['nickname']))
self.RefreshManagerLoop.start(self.REFRESH_INTERVAL)
示例3: runcase
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def runcase(alice_class, carol_class, fail_alice_state=None, fail_carol_state=None):
options_server = Options()
wallets = make_wallets(num_alices + 1,
wallet_structures=wallet_structures,
mean_amt=funding_amount)
args_server = ["dummy"]
test_data_server = (wallets[num_alices]['seed'], args_server, options_server,
False, None, carol_class, None, fail_carol_state)
carol_bbmb = main_cs(test_data_server)
options_alice = Options()
options_alice.serve = False
alices = []
for i in range(num_alices):
args_alice = ["dummy", amounts[i]]
if dest_addr:
args_alice.append(dest_addr)
test_data_alice = (wallets[i]['seed'], args_alice, options_alice, False,
alice_class, None, fail_alice_state, None)
alices.append(main_cs(test_data_alice))
l = task.LoopingCall(miner)
reactor.callWhenRunning(start_mining, l)
reactor.run()
return (alices, carol_bbmb, wallets[num_alices]['wallet'])
示例4: send_tx4_sig
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def send_tx4_sig(self):
"""Send partial signature on TX4 (out of TX0)
to Carol for her to complete sign and broadcast.
"""
utxo_in = self.tx0.txid + ":" + str(self.tx0.pay_out_index)
self.tx4 = CoinSwapTX45.from_params(self.coinswap_parameters.pubkeys["key_2_2_AC_0"],
self.coinswap_parameters.pubkeys["key_2_2_AC_1"],
utxo_in=utxo_in,
destination_address=self.coinswap_parameters.output_addresses["tx4_address"],
destination_amount=self.coinswap_parameters.tx4_amounts["carol"],
carol_change_address=None,
carol_change_amount=None)
self.tx4.sign_at_index(self.keyset["key_2_2_AC_0"][0], 0)
sig = self.tx4.signatures[0][0]
self.send(sig, self.tx5.txid)
self.tx4broadcast_counter = 0
self.loop_tx4 = task.LoopingCall(self.wait_for_tx4_confirmation)
self.loop_tx4.start(3.0)
return (True, "TX4 signature sent.")
示例5: push_tx1
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def push_tx1(self):
"""Having seen TX0 confirmed, broadcast TX1 and wait for confirmation.
"""
errmsg, success = self.tx1.push()
if not success:
return (False, "Failed to push TX1")
#Monitor the output address of TX1 by importing
cs_single().bc_interface.rpc("importaddress",
[self.tx1.output_address, "joinmarket-notify", False])
#Wait until TX1 seen before confirming phase2 ready.
self.loop = task.LoopingCall(self.check_for_phase1_utxos,
[self.tx1.txid + ":" + str(
self.tx1.pay_out_index)],
self.receive_confirmation_tx_0_1)
self.loop.start(3.0)
return (True, "TX1 broadcast OK")
示例6: _checkLoop
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def _checkLoop(self):
"""
Start or stop a C{LoopingCall} based on whether there are readers and
writers.
"""
if self._readers or self._writers:
if self._loop is None:
from twisted.internet.task import LoopingCall, _EPSILON
self._loop = LoopingCall(self.iterate)
self._loop.clock = self._reactor
# LoopingCall seems unhappy with timeout of 0, so use very
# small number:
self._loop.start(_EPSILON, now=False)
elif self._loop:
self._loop.stop()
self._loop = None
示例7: test_reset
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def test_reset(self):
"""
Test that L{LoopingCall} can be reset.
"""
ran = []
def foo():
ran.append(None)
c = task.Clock()
lc = TestableLoopingCall(c, foo)
lc.start(2, now=False)
c.advance(1)
lc.reset()
c.advance(1)
self.assertEqual(ran, [])
c.advance(1)
self.assertEqual(ran, [None])
示例8: test_deferredDeprecation
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def test_deferredDeprecation(self):
"""
L{LoopingCall.deferred} is deprecated.
"""
loop = task.LoopingCall(lambda: None)
loop.deferred
message = (
'twisted.internet.task.LoopingCall.deferred was deprecated in '
'Twisted 16.0.0; '
'please use the deferred returned by start() instead'
)
warnings = self.flushWarnings([self.test_deferredDeprecation])
self.assertEqual(1, len(warnings))
self.assertEqual(DeprecationWarning, warnings[0]['category'])
self.assertEqual(message, warnings[0]['message'])
示例9: loopUntil
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def loopUntil(predicate, interval=0):
"""
Poor excuse for an event notification helper. This polls a condition and
calls back a Deferred when it is seen to be true.
Do not use this function.
"""
from twisted.internet import task
d = defer.Deferred()
def check():
res = predicate()
if res:
d.callback(res)
call = task.LoopingCall(check)
def stop(result):
call.stop()
return result
d.addCallback(stop)
d2 = call.start(interval)
d2.addErrback(d.errback)
return d
示例10: __init__
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def __init__(self, node, db, signing_key, ksize=20, alpha=3, storage=None):
"""
Create a server instance. This will start listening on the given port.
Args:
node: The node instance for this peer. It must contain (at minimum) an ID,
public key, ip address, and port.
ksize (int): The k parameter from the paper
alpha (int): The alpha parameter from the paper
storage: An instance that implements :interface:`~dht.storage.IStorage`
"""
self.ksize = ksize
self.alpha = alpha
self.log = Logger(system=self)
self.storage = storage or ForgetfulStorage()
self.node = node
self.protocol = KademliaProtocol(self.node, self.storage, ksize, db, signing_key)
self.refreshLoop = LoopingCall(self.refreshTable)
reactor.callLater(1800, self.refreshLoop.start, 3600)
示例11: __init__
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def __init__(self, db, ip_address, nat_type, testnet=False, relaying=False):
"""
Initialize the new protocol with the connection handler factory.
Args:
ip_address: a `tuple` of the (ip address, port) of ths node.
"""
self.ip_address = ip_address
self.testnet = testnet
self.ws = None
self.blockchain = None
self.processors = []
self.relay_node = None
self.nat_type = nat_type
self.vendors = db.vendors.get_vendors()
self.ban_score = BanScore(self)
self.factory = self.ConnHandlerFactory(self.processors, nat_type, self.relay_node, self.ban_score)
self.log = Logger(system=self)
self.keep_alive_loop = LoopingCall(self.keep_alive)
self.keep_alive_loop.start(30, now=False)
ConnectionMultiplexer.__init__(self, CryptoConnectionFactory(self.factory), self.ip_address[0], relaying)
示例12: __init__
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def __init__(self):
self.loop = LoopingCall(self.check_spectrum)
self.wifi_interface = None
self.scanner = None
self.analyzer_process = AnalyzerProcessProtocol(self)
self.spectrum_observers = []
self.analyzer_observers = []
airshark_interface_manager.add_observer(self)
示例13: __init__
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def __init__(self, filename, saveTimer):
self.filename = filename
self.saveTimer = saveTimer
# Setup looping call to keep chute list perisistant
if (self.saveTimer > 0):
self.repeater = LoopingCall(self.saveToDisk)
self.repeater.start(self.saveTimer)
示例14: __init__
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def __init__(self, factory):
WebSocketServerProtocol.__init__(self)
self.factory = factory
self.loop = LoopingCall(self.check_log)
self.log_provider = None
示例15: __init__
# 需要导入模块: from twisted.internet import task [as 别名]
# 或者: from twisted.internet.task import LoopingCall [as 别名]
def __init__(self, update_manager):
# Store set of update IDs that are in progress in order to avoid
# repeats.
self.updates_in_progress = set()
self.update_manager = update_manager
self.scheduled_call = task.LoopingCall(self.pull_update, _auto=True)
self.long_poll_started = False
self.use_long_poll = True