本文整理汇总了Python中crossbar.common.process.NativeProcessSession类的典型用法代码示例。如果您正苦于以下问题:Python NativeProcessSession类的具体用法?Python NativeProcessSession怎么用?Python NativeProcessSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NativeProcessSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onConnect
def onConnect(self):
"""
Called when the worker has connected to the node's management router.
"""
self._node_id = self.config.extra.node
self._worker_id = self.config.extra.worker
self._uri_prefix = u'crossbar.worker.{}'.format(self._worker_id)
NativeProcessSession.onConnect(self, False)
self._module_tracker = TrackingModuleReloader(snapshot=False)
self._profiles = {}
# flag indicating when worker is shutting down
self._is_shutting_down = False
# Jinja2 templates for Web (like WS status page et al)
#
templates_dir = os.path.abspath(pkg_resources.resource_filename("crossbar", "web/templates"))
self.log.debug("Using Web templates from {templates_dir}",
templates_dir=templates_dir)
self._templates = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_dir))
self.join(self.config.realm)
示例2: __init__
def __init__(self, node):
"""
:param node: The node singleton for this node controller session.
:type node: obj
"""
NativeProcessSession.__init__(self)
#self.debug = node.debug
self.debug = False
self.debug_app = False
## associated node
self._node = node
self._node_id = node._node_id
self._realm = node._realm
self.cbdir = self._node._cbdir
self._created = utcnow()
self._pid = os.getpid()
## map of worker processes: worker_id -> NativeWorkerProcess
self._workers = {}
self._management_transport = None
exit = Deferred()
示例3: onConnect
def onConnect(self):
# self._uri_prefix = 'crossbar.node.{}'.format(self.config.extra.node)
self._uri_prefix = 'crossbar.node.{}'.format(self._node_id)
NativeProcessSession.onConnect(self, False)
# self.join(self.config.realm)
self.join(self._realm)
示例4: onConnect
def onConnect(self):
self.log.debug("Connected to node management router")
NativeProcessSession.onConnect(self, False)
# self.join(self.config.realm)
self.join(self._realm)
示例5: onConnect
def onConnect(self):
self.log.debug("Connected to node management router")
# self._uri_prefix = u'crossbar.node.{}'.format(self.config.extra.node)
self._uri_prefix = u'crossbar.node.{}'.format(self._node_id)
NativeProcessSession.onConnect(self, False)
# self.join(self.config.realm)
self.join(self._realm)
示例6: onConnect
def onConnect(self):
"""
Called when the worker has connected to the node's management router.
"""
self._uri_prefix = 'crossbar.node.{}.worker.{}'.format(self.config.extra.node, self.config.extra.worker)
NativeProcessSession.onConnect(self, False)
self._module_tracker = TrackingModuleReloader(debug=True)
self.join(self.config.realm)
示例7: onJoin
def onJoin(self, details, publish_ready=True):
"""
Called when worker process has joined the node's management realm.
"""
yield NativeProcessSession.onJoin(self, details)
procs = [
# CPU affinity for this worker process
'get_cpu_affinity',
'set_cpu_affinity',
# PYTHONPATH used for this worker
'get_pythonpath',
'add_pythonpath',
# profiling control
'get_profilers',
'start_profiler',
'query_profile',
]
dl = []
for proc in procs:
uri = '{}.{}'.format(self._uri_prefix, proc)
self.log.debug("Registering management API procedure {proc}", proc=uri)
dl.append(self.register(getattr(self, proc), uri, options=RegisterOptions(details_arg='details')))
regs = yield DeferredList(dl)
self.log.debug("Registered {cnt} management API procedures", cnt=len(regs))
if publish_ready:
yield self.publish_ready()
示例8: onJoin
def onJoin(self, details, publish_ready = True):
"""
Called when worker process has joined the node's management realm.
"""
yield NativeProcessSession.onJoin(self, details)
procs = [
'get_cpu_affinity',
'set_cpu_affinity',
'get_pythonpath',
'add_pythonpath',
]
dl = []
for proc in procs:
uri = '{}.{}'.format(self._uri_prefix, proc)
if self.debug:
log.msg("Registering procedure '{}'".format(uri))
dl.append(self.register(getattr(self, proc), uri, options = RegisterOptions(details_arg = 'details', discloseCaller = True)))
regs = yield DeferredList(dl)
if self.debug:
log.msg("{} registered {} procedures".format(self.__class__.__name__, len(regs)))
if publish_ready:
yield self.publish_ready()
示例9: onJoin
def onJoin(self, details):
self.log.info("Joined realm '{realm}' on node management router", realm=details.realm)
# When a (native) worker process has connected back to the router of
# the node controller, the worker will publish this event
# to signal it's readyness.
#
def on_worker_ready(res):
id = res['id']
if id in self._workers:
ready = self._workers[id].ready
if not ready.called:
# fire the Deferred previously stored for
# signaling "worker ready"
ready.callback(id)
else:
self.log.error("Internal error: on_worker_ready() fired for process {process}, but already called earlier",
process=id)
else:
self.log.error("Internal error: on_worker_ready() fired for process {process}, but no process with that ID",
process=id)
self.subscribe(on_worker_ready, 'crossbar.node.{}.on_worker_ready'.format(self._node_id))
yield NativeProcessSession.onJoin(self, details)
# register node controller procedures: 'crossbar.node.<ID>.<PROCEDURE>'
#
procs = [
'shutdown',
'get_info',
'get_workers',
'get_worker_log',
'start_router',
'stop_router',
'start_container',
'stop_container',
'start_guest',
'stop_guest',
'start_websocket_testee',
'stop_websocket_testee',
]
dl = []
for proc in procs:
uri = '{}.{}'.format(self._uri_prefix, proc)
self.log.debug("Registering management API procedure {proc}", proc=uri)
dl.append(self.register(getattr(self, proc), uri, options=RegisterOptions(details_arg='details')))
regs = yield DeferredList(dl)
self.log.debug("Registered {cnt} management API procedures", cnt=len(regs))
self._started = utcnow()
self.publish(u"crossbar.node.on_ready", self._node_id)
self.log.debug("Node controller ready")
示例10: onConnect
def onConnect(self):
"""
Called when the worker has connected to the node's management router.
"""
self._uri_prefix = 'crossbar.node.{}.worker.{}'.format(self.config.extra.node, self.config.extra.worker)
NativeProcessSession.onConnect(self, False)
self._module_tracker = TrackingModuleReloader(debug=True)
self._profiles = {}
# Jinja2 templates for Web (like WS status page et al)
#
templates_dir = os.path.abspath(pkg_resources.resource_filename("crossbar", "web/templates"))
self.log.debug("Using Web templates from {templates_dir}",
templates_dir=templates_dir)
self._templates = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_dir))
self.join(self.config.realm)
示例11: __init__
def __init__(self, node):
"""
:param node: The node singleton for this node controller session.
:type node: obj
"""
NativeProcessSession.__init__(self, reactor=node._reactor)
# associated node
self._node = node
self._node_id = node._node_id
self._realm = node._realm
self.cbdir = self._node._cbdir
self._started = None
self._pid = os.getpid()
# map of worker processes: worker_id -> NativeWorkerProcess
self._workers = {}
self._shutdown_requested = False
示例12: onJoin
def onJoin(self, details):
# When a (native) worker process has connected back to the router of
# the node controller, the worker will publish this event
# to signal it's readyness.
#
def on_worker_ready(res):
id = res['id']
if id in self._workers:
ready = self._workers[id].ready
if not ready.called:
# fire the Deferred previously stored for
# signaling "worker ready"
ready.callback(id)
else:
self.log.error("INTERNAL ERROR: on_worker_ready() fired for process {process} - ready already called",
process=id)
else:
self.log.error("INTERNAL ERROR: on_worker_ready() fired for process {process} - no process with that ID",
process=id)
self.subscribe(on_worker_ready, 'crossbar.node.{}.on_worker_ready'.format(self._node_id))
yield NativeProcessSession.onJoin(self, details)
# register node controller procedures: 'crossbar.node.<ID>.<PROCEDURE>'
#
procs = [
'shutdown',
'start_management_transport',
'get_info',
'get_workers',
'get_worker_log',
'start_router',
'stop_router',
'start_container',
'stop_container',
'start_guest',
'stop_guest',
]
dl = []
for proc in procs:
uri = '{}.{}'.format(self._uri_prefix, proc)
self.log.debug("Registering procedure '{uri}'", uri=uri)
dl.append(self.register(getattr(self, proc), uri, options=RegisterOptions(details_arg='details')))
regs = yield DeferredList(dl)
self.log.debug("{me} registered {registers} procedures",
me=self.__class__.__name__, registers=len(regs))
示例13: onJoin
def onJoin(self, details, publish_ready=True):
"""
Called when worker process has joined the node's management realm.
"""
yield NativeProcessSession.onJoin(self, details)
# above upcall registers all our "@wamp.register(None)" methods
# setup SIGTERM handler to orderly shutdown the worker
def shutdown(sig, frame):
self.log.warn("Native worker received SIGTERM - shutting down ..")
self.shutdown()
signal.signal(signal.SIGTERM, shutdown)
# the worker is ready for work!
if publish_ready:
yield self.publish_ready()
示例14: onJoin
def onJoin(self, details, publish_ready=True):
"""
Called when worker process has joined the node's management realm.
"""
yield NativeProcessSession.onJoin(self, details)
procs = [
# orderly shutdown worker "from inside"
'shutdown',
# CPU affinity for this worker process
'get_cpu_count',
'get_cpu_affinity',
'set_cpu_affinity',
# PYTHONPATH used for this worker
'get_pythonpath',
'add_pythonpath',
# profiling control
'get_profilers',
'start_profiler',
'get_profile',
]
dl = []
for proc in procs:
uri = '{}.{}'.format(self._uri_prefix, proc)
self.log.debug("Registering management API procedure {proc}", proc=uri)
dl.append(self.register(getattr(self, proc), uri, options=RegisterOptions(details_arg='details')))
regs = yield DeferredList(dl)
self.log.debug("Registered {cnt} management API procedures", cnt=len(regs))
# setup SIGTERM handler to orderly shutdown the worker
def shutdown(sig, frame):
self.log.warn("Native worker received SIGTERM - shutting down ..")
self.shutdown()
signal.signal(signal.SIGTERM, shutdown)
# the worker is ready for work!
if publish_ready:
yield self.publish_ready()
示例15: onJoin
def onJoin(self, details):
from autobahn.wamp.types import SubscribeOptions
self.log.debug("Joined realm '{realm}' on node management router", realm=details.realm)
# When a (native) worker process has connected back to the router of
# the node controller, the worker will publish this event
# to signal it's readyness.
#
def on_worker_ready(res):
worker_id = res['id']
if worker_id in self._workers:
ready = self._workers[worker_id].ready
if not ready.called:
# fire the Deferred previously stored for
# signaling "worker ready"
ready.callback(worker_id)
else:
self.log.error("Internal error: on_worker_ready() fired for process {process}, but already called earlier",
process=worker_id)
else:
self.log.error("Internal error: on_worker_ready() fired for process {process}, but no process with that ID",
process=worker_id)
self.subscribe(on_worker_ready, u'crossbar.worker..on_worker_ready', SubscribeOptions(match=u'wildcard'))
yield NativeProcessSession.onJoin(self, details)
# above upcall registers procedures we have marked with @wamp.register(None)
# we need to catch SIGINT here to properly shutdown the
# node explicitly (a Twisted system trigger wouldn't allow us to distinguish
# different reasons/origins of exiting ..)
def signal_handler(signal, frame):
# the following will shutdown the Twisted reactor in the end
self.shutdown()
signal.signal(signal.SIGINT, signal_handler)
self._started = utcnow()
self.publish(u"crossbar.on_ready")
self.log.debug("Node controller ready")