本文整理汇总了Python中twisted.internet.reactor.callWhenRunning方法的典型用法代码示例。如果您正苦于以下问题:Python reactor.callWhenRunning方法的具体用法?Python reactor.callWhenRunning怎么用?Python reactor.callWhenRunning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.reactor
的用法示例。
在下文中一共展示了reactor.callWhenRunning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runcase
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [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'])
示例2: test_synchronousStop
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def test_synchronousStop(self):
"""
L{task.react} handles when the reactor is stopped just before the
returned L{Deferred} fires.
"""
def main(reactor):
d = defer.Deferred()
def stop():
reactor.stop()
d.callback(None)
reactor.callWhenRunning(stop)
return d
r = _FakeReactor()
exitError = self.assertRaises(
SystemExit, task.react, main, [], _reactor=r)
self.assertEqual(0, exitError.code)
示例3: test_run_apt_update_report_timestamp
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def test_run_apt_update_report_timestamp(self):
"""
The package-report-result message includes a timestamp of the apt
update run.
"""
message_store = self.broker_service.message_store
message_store.set_accepted_types(["package-reporter-result"])
self._make_fake_apt_update(err="")
deferred = Deferred()
def do_test():
self.reactor.advance(10)
result = self.reporter.run_apt_update()
def callback(ignore):
self.assertMessages(
message_store.get_pending_messages(),
[{"type": "package-reporter-result",
"report-timestamp": 10.0, "code": 0, "err": u""}])
result.addCallback(callback)
self.reactor.advance(0)
result.chainDeferred(deferred)
reactor.callWhenRunning(do_test)
return deferred
示例4: test_run_apt_update_report_apt_failure
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def test_run_apt_update_report_apt_failure(self):
"""
If L{PackageReporter.run_apt_update} fails, a message is sent to the
server reporting the error, to be able to fix the problem centrally.
"""
message_store = self.broker_service.message_store
message_store.set_accepted_types(["package-reporter-result"])
self._make_fake_apt_update(code=2)
deferred = Deferred()
def do_test():
result = self.reporter.run_apt_update()
def callback(ignore):
self.assertMessages(
message_store.get_pending_messages(),
[{"type": "package-reporter-result",
"report-timestamp": 0.0, "code": 2, "err": u"error"}])
result.addCallback(callback)
self.reactor.advance(0)
result.chainDeferred(deferred)
reactor.callWhenRunning(do_test)
return deferred
示例5: test_run_apt_update_report_apt_failure_no_sources
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def test_run_apt_update_report_apt_failure_no_sources(self):
"""
If L{PackageReporter.run_apt_update} fails and there are no
APT sources configured, the APT error takes precedence.
"""
self.facade.reset_channels()
message_store = self.broker_service.message_store
message_store.set_accepted_types(["package-reporter-result"])
self._make_fake_apt_update(code=2)
deferred = Deferred()
def do_test():
result = self.reporter.run_apt_update()
def callback(ignore):
self.assertMessages(
message_store.get_pending_messages(),
[{"type": "package-reporter-result",
"report-timestamp": 0.0, "code": 2, "err": u"error"}])
result.addCallback(callback)
self.reactor.advance(0)
result.chainDeferred(deferred)
reactor.callWhenRunning(do_test)
return deferred
示例6: test_run_apt_update_touches_stamp_file
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def test_run_apt_update_touches_stamp_file(self):
"""
The L{PackageReporter.run_apt_update} method touches a stamp file
after running the apt-update wrapper.
"""
self.reporter.sources_list_filename = "/I/Dont/Exist"
self._make_fake_apt_update()
deferred = Deferred()
def do_test():
result = self.reporter.run_apt_update()
def callback(ignored):
self.assertTrue(
os.path.exists(self.config.update_stamp_filename))
result.addCallback(callback)
self.reactor.advance(0)
result.chainDeferred(deferred)
reactor.callWhenRunning(do_test)
return deferred
示例7: test_fast_keyboard_interrupt_stops_test_run
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def test_fast_keyboard_interrupt_stops_test_run(self):
# If we get a SIGINT during a test run, the test stops and no more
# tests run.
SIGINT = getattr(signal, 'SIGINT', None)
if not SIGINT:
raise self.skipTest("SIGINT unavailable")
class SomeCase(TestCase):
def test_pause(self):
return defer.Deferred()
test = SomeCase('test_pause')
reactor = self.make_reactor()
timeout = self.make_timeout()
runner = self.make_runner(test, timeout * 5)
result = self.make_result()
reactor.callWhenRunning(os.kill, os.getpid(), SIGINT)
self.assertThat(lambda:runner.run(result),
Raises(MatchesException(KeyboardInterrupt)))
示例8: main
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def main():
plugins_dir = FilePath("/run/docker/plugins/")
if not plugins_dir.exists():
plugins_dir.makedirs()
dvol_path = FilePath("/var/lib/dvol/volumes")
if not dvol_path.exists():
dvol_path.makedirs()
voluminous = Voluminous(dvol_path.path)
sock = plugins_dir.child("%s.sock" % (VOLUME_DRIVER_NAME,))
if sock.exists():
sock.remove()
adapterServer = internet.UNIXServer(
sock.path, getAdapter(voluminous))
reactor.callWhenRunning(adapterServer.startService)
reactor.run()
示例9: initialize
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def initialize():
args = arguments.parse_maintenance_args()
logger.init(debug=args.debug)
@defer.inlineCallbacks
def _run():
leap_session = yield initialize_leap_single_user(
args.leap_provider_cert,
args.leap_provider_cert_fingerprint,
args.credentials_file,
leap_home=args.leap_home)
execute_command(args, leap_session)
reactor.callWhenRunning(_run)
reactor.run()
示例10: initialize
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def initialize():
logger_config.init(debug=False)
args = arguments.parse_register_args()
leap_provider = _set_leap_provider(args)
def show_error(err):
logger.info('error: %s' % err)
def shut_down(_):
reactor.stop()
def _register():
d = register(
args.username,
args.password,
leap_provider,
args.invite_code)
d.addErrback(show_error)
d.addBoth(shut_down)
reactor.callWhenRunning(_register)
reactor.run()
示例11: run
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def run():
args = _parse_args()
def show_error(err):
print "ERROR: %s" % err.getErrorMessage()
def shut_down(_):
reactor.stop()
def _run():
d = mass_register(args.number, args.invite_code, args.provider)
d.addErrback(show_error)
d.addBoth(shut_down)
reactor.callWhenRunning(_run)
reactor.run()
示例12: install_default_pool
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def install_default_pool(maxthreads=max_threads_for_default_pool):
"""Install a custom pool as Twisted's global/reactor thread-pool.
Disallow all database activity in the reactor thread-pool. Why such a
strict policy? We've been following Django's model, where threads and
database connections are wedded together. In MAAS this limits concurrency,
contributes to crashes and deadlocks, and has spawned workarounds like
post-commit hooks. From here on, using a database connection requires the
use of a specific, separate, carefully-sized, thread-pool.
"""
if reactor.threadpool is None:
# Start with ZERO threads to avoid pulling in all of Django's
# configuration straight away; it may not be ready yet.
reactor.threadpool = make_default_pool(maxthreads)
reactor.callWhenRunning(reactor.threadpool.start)
reactor.addSystemEventTrigger(
"during", "shutdown", reactor.threadpool.stop
)
else:
raise AssertionError(
"Too late; global/reactor thread-pool has "
"already been configured and installed."
)
示例13: install_database_pool
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def install_database_pool(maxthreads=max_threads_for_database_pool):
"""Install a pool for database activity."""
if getattr(reactor, "threadpoolForDatabase", None) is None:
# Start with ZERO threads to avoid pulling in all of Django's
# configuration straight away; it may not be ready yet.
reactor.threadpoolForDatabase = make_database_pool(maxthreads)
reactor.callInDatabase = reactor.threadpoolForDatabase.callInThread
reactor.callWhenRunning(reactor.threadpoolForDatabase.start)
reactor.addSystemEventTrigger(
"during", "shutdown", reactor.threadpoolForDatabase.stop
)
else:
raise AssertionError(
"Too late; database thread-pool has already "
"been configured and installed."
)
示例14: install_database_unpool
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def install_database_unpool(maxthreads=max_threads_for_database_pool):
"""Install a pool for database activity particularly suited to testing.
See `make_database_unpool` for details.
"""
try:
reactor.threadpoolForDatabase
except AttributeError:
reactor.threadpoolForDatabase = make_database_unpool(maxthreads)
reactor.callInDatabase = reactor.threadpoolForDatabase.callInThread
reactor.callWhenRunning(reactor.threadpoolForDatabase.start)
reactor.addSystemEventTrigger(
"during", "shutdown", reactor.threadpoolForDatabase.stop
)
else:
raise AssertionError(
"Too late; database thread-pool has already "
"been configured and installed."
)
示例15: _processClientActions
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callWhenRunning [as 别名]
def _processClientActions(self):
log.debug("Processing Client Actions...")
while self.clientActions:
session, action = self.clientActions.pop(0)
servername = action['server'][0]
role, handler = self.actionHandlers.get(action['action'][0], (None, None))
if handler:
if self.authRequired:
if role in self.authUsers[session.username].servers.get(servername):
reactor.callWhenRunning(handler, session, action)
else:
self.http._addUpdate(servername = servername, sessid = session.uid, action = "RequestError", message = "You do not have permission to execute this action.")
else:
reactor.callWhenRunning(handler, session, action)
else:
log.error("ClientActionHandler for action %s does not exixts..." % action['action'][0])