本文整理匯總了Python中twisted.internet.reactor.running方法的典型用法代碼示例。如果您正苦於以下問題:Python reactor.running方法的具體用法?Python reactor.running怎麽用?Python reactor.running使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.reactor
的用法示例。
在下文中一共展示了reactor.running方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: execute
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def execute():
cfg = Configuration(".bitmaskctl")
print_json = '--json' in sys.argv
cli = BitmaskCLI(cfg)
cli.data = ['core', 'version']
args = None if '--noverbose' in sys.argv else ['--verbose']
if should_start(sys.argv):
timeout_fun = cli.start
else:
def status_timeout(args):
raise RuntimeError('bitmaskd is not running')
timeout_fun = status_timeout
try:
yield cli._send(
timeout=0.1, printer=_null_printer,
errb=lambda: timeout_fun(args))
except Exception, e:
print(Fore.RED + "ERROR: " + Fore.RESET +
"%s" % str(e))
yield reactor.stop()
示例2: signal_handler
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def signal_handler(signal, frame):
global _user_abort
state_machine_execution_engine = core_singletons.state_machine_execution_engine
core_singletons.shut_down_signal = signal
logger.info("Shutting down ...")
try:
if not state_machine_execution_engine.finished_or_stopped():
state_machine_execution_engine.stop()
state_machine_execution_engine.join(3) # Wait max 3 sec for the execution to stop
except Exception:
logger.exception("Could not stop state machine")
_user_abort = True
# shutdown twisted correctly
if reactor_required():
from twisted.internet import reactor
if reactor.running:
plugins.run_hook("pre_destruction")
reactor.callFromThread(reactor.stop)
logging.shutdown()
示例3: test_check_daemons
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def test_check_daemons(self):
"""
The daemons are checked to be running every so often. When N=5 of these
checks fail, the daemon will be restarted.
"""
clock = Clock()
dog = WatchDog(clock,
broker=AsynchronousPingDaemon("test-broker"),
monitor=AsynchronousPingDaemon("test-monitor"),
manager=AsynchronousPingDaemon("test-manager"))
dog.start_monitoring()
for i in range(4):
clock.advance(5)
dog.broker.fire_running(False)
dog.monitor.fire_running(True)
dog.manager.fire_running(True)
self.assertEqual(dog.broker.boots, [])
clock.advance(5)
dog.broker.fire_running(False)
dog.monitor.fire_running(True)
dog.manager.fire_running(True)
self.assertEqual(dog.broker.boots, [STOP, START])
示例4: test_dont_write_pid_file_until_we_really_start
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def test_dont_write_pid_file_until_we_really_start(
self, mock_watchdog, mock_daemonize, mock_reactor):
"""
If the client can't be started because another client is still running,
the client shouldn't be daemonized and the pid file shouldn't be
written.
"""
mock_watchdog().check_running.return_value = succeed([StubDaemon()])
mock_reactor.crash.return_value = None
self.log_helper.ignore_errors(
"ERROR: The following daemons are already running: program-name")
pid_file = self.makeFile()
self.configuration.daemon = True
self.configuration.pid_file = pid_file
service = WatchDogService(self.configuration)
service.startService()
self.assertFalse(os.path.exists(pid_file))
mock_daemonize.assert_not_called()
mock_watchdog().check_running.assert_called_once_with()
mock_watchdog().start.assert_not_called()
mock_reactor.crash.assert_called_once_with()
示例5: start_wallet_monitoring
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def start_wallet_monitoring(self, syncresult):
""" Once the initialization of the service
(currently, means: wallet sync) is complete,
we start the main monitoring jobs of the
wallet service (currently, means: monitoring
all new transactions on the blockchain that
are recognised as belonging to the Bitcoin
Core wallet with the JM wallet's label).
"""
if not syncresult:
jlog.error("Failed to sync the bitcoin wallet. Shutting down.")
self.stopService()
if reactor.running:
reactor.stop()
return
jlog.info("Starting transaction monitor in walletservice")
self.monitor_loop = task.LoopingCall(
self.transaction_monitor)
self.monitor_loop.start(5.0)
示例6: toggleButtons
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def toggleButtons(self):
"""Refreshes accessibility of buttons in the (single, multiple) join
tabs based on the current state as defined by the SpendStateMgr instance.
Thus, should always be called on any update to that instance.
"""
#The first two buttons are for the single join tab; the remaining 4
#are for the multijoin tab.
btns = (self.startButton, self.abortButton,
self.schedule_set_button, self.schedule_generate_button,
self.sch_startButton, self.sch_abortButton)
if self.spendstate.runstate == 'ready':
btnsettings = (True, False, True, True, True, False)
elif self.spendstate.runstate == 'running':
if self.spendstate.typestate == 'single':
#can only abort current run, nothing else
btnsettings = (False, True, False, False, False, False)
elif self.spendstate.typestate == 'multiple':
btnsettings = (False, False, False, False, False, True)
else:
assert False
else:
assert False
for b, s in zip(btns, btnsettings):
b.setEnabled(s)
示例7: execute_from_command_line
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def execute_from_command_line():
# Limit concurrency in all thread-pools to ONE.
from maasserver.utils import threads
threads.install_default_pool(maxthreads=1)
threads.install_database_unpool(maxthreads=1)
# Disable all database connections in the reactor.
from maasserver.utils import orm
from twisted.internet import reactor
assert not reactor.running, "The reactor has been started too early."
reactor.callFromThread(orm.disable_all_database_connections)
# Configure logging; Django is no longer responsible for this. Behave as
# if we're always at an interactive terminal (i.e. do not wrap stdout or
# stderr with log machinery).
from provisioningserver import logger
logger.configure(mode=logger.LoggingMode.COMMAND)
# Hand over to Django.
from django.core import management
management.execute_from_command_line()
示例8: calc_iteration
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def calc_iteration(self):
if not self.running or not reactor.running:
debug(1, '%s exiting', self)
return False
if not self.last_t:
self.last_t = time()
now = time()
if now - self.last_t >= self.period:
self.rate = self.alpha*self.rate + \
(1.0-self.alpha)*self.last_data/(now - self.last_t)
self.last_data = 0
self.last_t = now
self.rate_vec.add(self.rate)
#self.rate_filt = self.harmonic_mean(self.rate_vec.getBuffer())
self.emit('update')
reactor.callLater(self.period, self.calc_iteration)
#return True
示例9: connectionLost
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def connectionLost(self, reason=None):
"""
Called by Twisted when the connection is gone. Regardless of whether
it was clean or not, we want to stop the reactor.
"""
if self.fileobj is not None:
self.fileobj.close()
if reactor.running:
reactor.stop()
示例10: processEnded
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def processEnded(self, reason):
log.info("Checker process ended with reason: {reason}", reason=reason)
if reactor.running:
reactor.stop()
示例11: onExitSignal
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def onExitSignal(*a):
print 'Closing Timeline?'
if not reactor.running:
os._exit(1)
reactor.callFromThread(reactor.stop)
示例12: start
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def start(self, raw_args):
# XXX careful! Should see if the process in PID is running,
# avoid launching again.
import commands
cmd = 'bitmaskd'
if raw_args and ('--verbose' in raw_args or '-v' in raw_args):
cmd += ' --verbose'
commands.getoutput(cmd)
self.cfg.set('bonafide', 'active', "")
return defer.succeed(None)
示例13: main
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def main():
def signal_handler(signal, frame):
if reactor.running:
reactor.stop()
sys.exit(0)
reactor.callWhenRunning(reactor.callLater, 0, execute)
signal.signal(signal.SIGINT, signal_handler)
reactor.run()
示例14: clientConnectionFailed
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def clientConnectionFailed(self, connector, reason):
self.rx._callback('error', 'connection %s failed, reason=%s' % (connector, reason))
if reactor.running:
try:
reactor.stop()
except error.ReactorNotRunning:
pass
示例15: clientConnectionLost
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import running [as 別名]
def clientConnectionLost(self, connector, reason):
self.rx._callback('error', 'connection %s lost, reason=%s' % (connector, reason))
if reactor.running:
try:
reactor.stop()
except error.ReactorNotRunning:
pass