本文整理匯總了Python中clacks.common.components.PluginRegistry.shutdown方法的典型用法代碼示例。如果您正苦於以下問題:Python PluginRegistry.shutdown方法的具體用法?Python PluginRegistry.shutdown怎麽用?Python PluginRegistry.shutdown使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類clacks.common.components.PluginRegistry
的用法示例。
在下文中一共展示了PluginRegistry.shutdown方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: shutdown
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import shutdown [as 別名]
def shutdown(a=None, b=None):
""" Function to shut down the agent. Do some clean up and close sockets."""
global dr
amqp = PluginRegistry.getInstance("AMQPHandler")
# Tell others that we're away now
if hasattr(amqp, 'env'):
e = EventMaker()
goodbye = e.Event(e.NodeLeave(e.Id(amqp.env.id)))
amqp.sendEvent(goodbye)
# Shutdown plugins
PluginRegistry.shutdown()
dr.stop()
logging.info("shut down")
logging.shutdown()
示例2: mainLoop
# 需要導入模塊: from clacks.common.components import PluginRegistry [as 別名]
# 或者: from clacks.common.components.PluginRegistry import shutdown [as 別名]
def mainLoop(env):
""" Main event loop which will process all registerd threads in a loop.
It will run as long env.active is set to True."""
global dr
# Enable DBus runner
dr = DBusRunner()
dr.start()
log = logging.getLogger(__name__)
try:
while True:
# Load plugins
oreg = ObjectRegistry.getInstance() #@UnusedVariable
pr = PluginRegistry() #@UnusedVariable
cr = PluginRegistry.getInstance("CommandRegistry")
amqp = PluginRegistry.getInstance("AMQPHandler")
index = PluginRegistry.getInstance("ObjectIndex")
wait = 2
notifyInterval = 10
interval = notifyInterval
loadAvg = SystemLoad()
# Sleep and slice
while True:
# Threading doesn't seem to work well with python...
for p in env.threads:
# Bail out if we're active in the meanwhile
if not env.active:
break
# Check if we reached the notification interval
interval += wait
if interval > notifyInterval:
interval = 0
load = loadAvg.getLoad()
latency = 0
workers = len(env.threads)
log.debug("load %s, latency %s, workers %s" %
(load, latency, workers))
e = EventMaker()
status = e.Event(
e.NodeStatus(
e.Id(env.id),
e.Load(str(load)),
e.Latency(str(latency)),
e.Workers(str(workers)),
e.Indexed("true" if index.index_active() else
"false"),
)
)
amqp.sendEvent(status)
# Disable potentially dead nodes
cr.updateNodes()
p.join(wait)
# No break, go to main loop
else:
continue
# Leave the thread loop
break
# Break, leave main loop
if not env.reset_requested:
break
# Wait for threads to shut down
for t in env.threads:
t.join(wait)
if hasattr(t, 'stop'):
t.stop()
# Lets do an environment reset now
PluginRegistry.shutdown()
# Make us active and loop from the beginning
env.reset_requested = False
env.active = True
# Catchall, pylint: disable=W0703
except Exception as detail:
log.critical("unexpected error in mainLoop")
log.exception(detail)
except KeyboardInterrupt:
log.info("console requested shutdown")
finally:
shutdown()