本文整理汇总了Python中circus.controller.Controller.start方法的典型用法代码示例。如果您正苦于以下问题:Python Controller.start方法的具体用法?Python Controller.start怎么用?Python Controller.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类circus.controller.Controller
的用法示例。
在下文中一共展示了Controller.start方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Arbiter
# 需要导入模块: from circus.controller import Controller [as 别名]
# 或者: from circus.controller.Controller import start [as 别名]
class Arbiter(object):
"""Class used to control a list of watchers.
Options:
- **watchers** -- a list of Watcher objects
- **endpoint** -- the controller ZMQ endpoint
- **pubsub_endpoint** -- the pubsub endpoint
- **stats_endpoint** -- the stats endpoint. If not provided,
the *circusd-stats* process will not be launched.
- **check_delay** -- the delay between two controller points
(default: 1 s)
- **prereload_fn** -- callable that will be executed on each reload
(default: None)
- **context** -- if provided, the zmq context to reuse.
(default: None)
- **loop**: if provided, a :class:`zmq.eventloop.ioloop.IOLoop` instance
to reuse. (default: None)
- **plugins** -- a list of plugins. Each item is a mapping with:
- **use** -- Fully qualified name that points to the plugin class
- every other value is passed to the plugin in the **config** option
"""
def __init__(self, watchers, endpoint, pubsub_endpoint, check_delay=1.,
prereload_fn=None, context=None, loop=None,
stats_endpoint=None, plugins=None):
self.watchers = watchers
self.endpoint = endpoint
self.check_delay = check_delay
self.prereload_fn = prereload_fn
self.pubsub_endpoint = pubsub_endpoint
# initialize zmq context
self.context = context or zmq.Context.instance()
self.loop = loop or ioloop.IOLoop()
self.ctrl = Controller(endpoint, self.context, self.loop, self,
check_delay)
self.pid = os.getpid()
self._watchers_names = {}
self.alive = True
self._lock = RLock()
# initializing circusd-stats as a watcher when configured
self.stats_endpoint = stats_endpoint
if self.stats_endpoint is not None:
cmd = "%s -c 'from circus import stats; stats.main()'" % \
sys.executable
cmd += ' --endpoint %s' % self.endpoint
cmd += ' --pubsub %s' % self.pubsub_endpoint
cmd += ' --statspoint %s' % self.stats_endpoint
stats_watcher = Watcher('circusd-stats', cmd)
self.watchers.append(stats_watcher)
self.plugins = plugins
self._plugins = {}
def _stop_plugins(self):
for plugin in self._plugins.values():
if not plugin.running:
continue
plugin.stop()
def _start_plugins(self):
self._stop_plugins()
self._plugins.clear()
if self.plugins is None:
return
for config in self.plugins:
fqn = config['use']
del config['use']
cls = resolve_name(fqn)
instance = cls(self.context, self.endpoint,
self.pubsub_endpoint, self.check_delay,
**config)
self._plugins[cls.name] = instance
for plugin in self._plugins.values():
if not plugin.active:
continue
plugin.start()
@classmethod
def load_from_config(cls, config_file):
cfg = get_config(config_file)
# hack reload ioloop to use the monkey patched version
reload(ioloop)
watchers = []
for watcher in cfg.get('watchers', []):
watchers.append(Watcher.load_from_config(watcher))
# creating arbiter
arbiter = cls(watchers, cfg['endpoint'], cfg['pubsub_endpoint'],
check_delay=cfg.get('check_delay', 1.),
prereload_fn=cfg.get('prereload_fn'),
stats_endpoint=cfg.get('stats_endpoint'),
#.........这里部分代码省略.........
示例2: Arbiter
# 需要导入模块: from circus.controller import Controller [as 别名]
# 或者: from circus.controller.Controller import start [as 别名]
class Arbiter(object):
"""Class used to control a list of watchers.
Options:
- **watchers** -- a list of Watcher objects
- **endpoint** -- the controller ZMQ endpoint
- **pubsub_endpoint** -- the pubsub endpoint
- **statsd** -- If True, a circusd-stats process is run (default: False)
- **stats_endpoint** -- the stats endpoint.
- **statsd_close_outputs** -- if True sends the circusd-stats stdout/stderr
to /dev/null (default: False)
- **multicast_endpoint** -- the multicast endpoint for circusd cluster
auto-discovery (default: udp://237.219.251.97:12027)
Multicast addr should be between 224.0.0.0 to 239.255.255.255 and the
same for the all cluster.
- **check_delay** -- the delay between two controller points
(default: 1 s)
- **prereload_fn** -- callable that will be executed on each reload
(default: None)
- **context** -- if provided, the zmq context to reuse.
(default: None)
- **loop**: if provided, a :class:`zmq.eventloop.ioloop.IOLoop` instance
to reuse. (default: None)
- **plugins** -- a list of plugins. Each item is a mapping with:
- **use** -- Fully qualified name that points to the plugin class
- every other value is passed to the plugin in the **config** option
- **sockets** -- a mapping of sockets. Each key is the socket name,
and each value a :class:`CircusSocket` class. (default: None)
- **warmup_delay** -- a delay in seconds between two watchers startup.
(default: 0)
- **httpd** -- If True, a circushttpd process is run (default: False)
- **httpd_host** -- the circushttpd host (default: localhost)
- **httpd_port** -- the circushttpd port (default: 8080)
- **httpd_close_outputs** -- if True, sends circushttpd stdout/stderr
to /dev/null. (default: False)
- **debug** -- if True, adds a lot of debug info in the stdout (default:
False)
- **debug_gc** -- if True, does gc.set_debug(gc.DEBUG_LEAK) (default:
False)
to circusd to analyze problems (default: False)
- **proc_name** -- the arbiter process name
- **fqdn_prefix** -- a prefix for the unique identifier of the circus
instance on the cluster.
- **endpoint_owner** -- unix user to chown the endpoint to if using ipc.
"""
def __init__(self, watchers, endpoint, pubsub_endpoint, check_delay=1.0,
prereload_fn=None, context=None, loop=None, statsd=False,
stats_endpoint=None, statsd_close_outputs=False,
multicast_endpoint=None, plugins=None,
sockets=None, warmup_delay=0, httpd=False,
httpd_host='localhost', httpd_port=8080,
httpd_close_outputs=False, debug=False, debug_gc=False,
ssh_server=None, proc_name='circusd', pidfile=None,
loglevel=None, logoutput=None, loggerconfig=None,
fqdn_prefix=None, umask=None, endpoint_owner=None):
self.watchers = watchers
self.endpoint = endpoint
self.check_delay = check_delay
self.prereload_fn = prereload_fn
self.pubsub_endpoint = pubsub_endpoint
self.multicast_endpoint = multicast_endpoint
self.proc_name = proc_name
self.ssh_server = ssh_server
self.evpub_socket = None
self.pidfile = pidfile
self.loglevel = loglevel
self.logoutput = logoutput
self.loggerconfig = loggerconfig
self.umask = umask
self.endpoint_owner = endpoint_owner
self._running = False
try:
# getfqdn appears to fail in Python3.3 in the unittest
# framework so fall back to gethostname
socket_fqdn = socket.getfqdn()
except KeyError:
socket_fqdn = socket.gethostname()
if fqdn_prefix is None:
fqdn = socket_fqdn
else:
fqdn = '{}@{}'.format(fqdn_prefix, socket_fqdn)
self.fqdn = fqdn
self.ctrl = self.loop = None
self._provided_loop = False
self.socket_event = False
if loop is not None:
self._provided_loop = True
self.loop = loop
# initialize zmq context
self._init_context(context)
self.pid = os.getpid()
self._watchers_names = {}
self._stopping = False
#.........这里部分代码省略.........
示例3: Arbiter
# 需要导入模块: from circus.controller import Controller [as 别名]
# 或者: from circus.controller.Controller import start [as 别名]
class Arbiter(object):
"""Class used to control a list of watchers.
Options:
- **watchers** -- a list of Watcher objects
- **endpoint** -- the controller ZMQ endpoint
- **pubsub_endpoint** -- the pubsub endpoint
- **stats_endpoint** -- the stats endpoint. If not provided,
the *circusd-stats* process will not be launched.
- **check_delay** -- the delay between two controller points
(default: 1 s)
- **prereload_fn** -- callable that will be executed on each reload
(default: None)
- **context** -- if provided, the zmq context to reuse.
(default: None)
- **loop**: if provided, a :class:`zmq.eventloop.ioloop.IOLoop` instance
to reuse. (default: None)
- **plugins** -- a list of plugins. Each item is a mapping with:
- **use** -- Fully qualified name that points to the plugin class
- every other value is passed to the plugin in the **config** option
- **sockets** -- a mapping of sockets. Each key is the socket name,
and each value a :class:`CircusSocket` class. (default: None)
- **warmup_delay** -- a delay in seconds between two watchers startup.
(default: 0)
- **httpd** -- If True, a circushttpd process is run (default: False)
- **httpd_host** -- the circushttpd host (default: localhost)
- **httpd_port** -- the circushttpd port (default: 8080)
- **debug** -- if True, adds a lot of debug info in the stdout (default:
False)
- **stream_backend** -- the backend that will be used for the streaming
process. Can be *thread* or *gevent*. When set to *gevent* you need
to have *gevent* and *gevent_zmq* installed.
All watchers will use this setup unless stated otherwise in the
watcher configuration. (default: thread)
- **proc_name** -- the arbiter process name
"""
def __init__(self, watchers, endpoint, pubsub_endpoint, check_delay=1.,
prereload_fn=None, context=None, loop=None,
stats_endpoint=None, plugins=None, sockets=None,
warmup_delay=0, httpd=False, httpd_host='localhost',
httpd_port=8080, debug=False, stream_backend='thread',
ssh_server=None, proc_name='circusd'):
self.stream_backend = stream_backend
self.watchers = watchers
self.endpoint = endpoint
self.check_delay = check_delay
self.prereload_fn = prereload_fn
self.pubsub_endpoint = pubsub_endpoint
self.proc_name = proc_name
# initialize zmq context
self.context = context or zmq.Context.instance()
self.loop = loop or ioloop.IOLoop()
self.ctrl = Controller(endpoint, self.context, self.loop, self,
check_delay)
self.pid = os.getpid()
self._watchers_names = {}
self.alive = True
self._lock = RLock()
self.debug = debug
if self.debug:
stdout_stream = stderr_stream = {'class': 'StdoutStream'}
else:
stdout_stream = stderr_stream = None
# initializing circusd-stats as a watcher when configured
self.stats_endpoint = stats_endpoint
if self.stats_endpoint is not None:
cmd = "%s -c 'from circus import stats; stats.main()'" % \
sys.executable
cmd += ' --endpoint %s' % self.endpoint
cmd += ' --pubsub %s' % self.pubsub_endpoint
cmd += ' --statspoint %s' % self.stats_endpoint
if ssh_server is not None:
cmd += ' --ssh %s' % ssh_server
if debug:
cmd += ' --log-level DEBUG'
stats_watcher = Watcher('circusd-stats', cmd, use_sockets=True,
singleton=True,
stdout_stream=stdout_stream,
stderr_stream=stderr_stream,
stream_backend=self.stream_backend,
copy_env=True, copy_path=True)
self.watchers.append(stats_watcher)
# adding the httpd
if httpd:
cmd = ("%s -c 'from circus.web import circushttpd; "
"circushttpd.main()'") % sys.executable
cmd += ' --endpoint %s' % self.endpoint
cmd += ' --fd $(circus.sockets.circushttpd)'
if ssh_server is not None:
cmd += ' --ssh %s' % ssh_server
httpd_watcher = Watcher('circushttpd', cmd, use_sockets=True,
singleton=True,
stdout_stream=stdout_stream,
stderr_stream=stderr_stream,
#.........这里部分代码省略.........
示例4: Arbiter
# 需要导入模块: from circus.controller import Controller [as 别名]
# 或者: from circus.controller.Controller import start [as 别名]
class Arbiter(object):
"""Class used to control a list of watchers.
Options:
- **watchers**: a list of Watcher objects
- **endpoint**: the controller ZMQ endpoint
- **pubsub_endpoint**: the pubsub endpoint
- **check_delay**: the delay between two controller points (default: 1 s)
- **prereload_fn**: callable that will be executed on each reload
(default: None)
"""
def __init__(
self,
watchers,
endpoint,
pubsub_endpoint,
check_delay=1.0,
prereload_fn=None,
context=None,
loop=None,
check_flapping=True,
):
self.watchers = watchers
self.endpoint = endpoint
self.check_delay = check_delay
self.prereload_fn = prereload_fn
self.pubsub_endpoint = pubsub_endpoint
# initialize zmq context
self.context = context or zmq.Context.instance()
self.loop = loop or ioloop.IOLoop()
self.ctrl = Controller(endpoint, self.context, self.loop, self, check_delay)
self.pid = os.getpid()
self._watchers_names = {}
self.alive = True
self.busy = False
self.check_flapping = check_flapping
@debuglog
def initialize(self):
# event pub socket
self.evpub_socket = self.context.socket(zmq.PUB)
self.evpub_socket.bind(self.pubsub_endpoint)
self.evpub_socket.linger = 0
# initialize flapping
if self.check_flapping:
self.flapping = Flapping(self.context, self.endpoint, self.pubsub_endpoint, self.check_delay)
# initialize watchers
for watcher in self.watchers:
self._watchers_names[watcher.name.lower()] = watcher
watcher.initialize(self.evpub_socket)
@debuglog
def start(self):
"""Starts all the watchers.
The start command is an infinite loop that waits
for any command from a client and that watches all the
processes and restarts them if needed.
"""
logger.info("Starting master on pid %s", self.pid)
self.initialize()
# start controller
self.ctrl.start()
# start flapping
if self.check_flapping:
logger.debug("Starting flapping")
self.flapping.start()
# initialize processes
logger.debug("Initializing watchers")
for watcher in self.watchers:
watcher.start()
logger.info("Arbiter now waiting for commands")
while True:
try:
self.loop.start()
except zmq.ZMQError as e:
if e.errno == errno.EINTR:
continue
else:
raise
else:
break
if self.check_flapping:
self.flapping.stop()
self.ctrl.stop()
self.evpub_socket.close()
#.........这里部分代码省略.........
示例5: Arbiter
# 需要导入模块: from circus.controller import Controller [as 别名]
# 或者: from circus.controller.Controller import start [as 别名]
class Arbiter(object):
"""Class used to control a list of watchers.
Options:
- **watchers** -- a list of Watcher objects
- **endpoint** -- the controller ZMQ endpoint
- **pubsub_endpoint** -- the pubsub endpoint
- **statsd** -- If True, a circusd-stats process is run (default: False)
- **stats_endpoint** -- the stats endpoint.
- **statsd_close_outputs** -- if True sends the circusd-stats stdout/stderr
to /dev/null (default: False)
- **multicast_endpoint** -- the multicast endpoint for circusd cluster
auto-discovery (default: udp://237.219.251.97:12027)
Multicast addr should be between 224.0.0.0 to 239.255.255.255 and the
same for the all cluster.
- **check_delay** -- the delay between two controller points
(default: 1 s)
- **prereload_fn** -- callable that will be executed on each reload
(default: None)
- **context** -- if provided, the zmq context to reuse.
(default: None)
- **loop**: if provided, a :class:`zmq.eventloop.ioloop.IOLoop` instance
to reuse. (default: None)
- **plugins** -- a list of plugins. Each item is a mapping with:
- **use** -- Fully qualified name that points to the plugin class
- every other value is passed to the plugin in the **config** option
- **sockets** -- a mapping of sockets. Each key is the socket name,
and each value a :class:`CircusSocket` class. (default: None)
- **warmup_delay** -- a delay in seconds between two watchers startup.
(default: 0)
- **httpd** -- If True, a circushttpd process is run (default: False)
- **httpd_host** -- the circushttpd host (default: localhost)
- **httpd_port** -- the circushttpd port (default: 8080)
- **httpd_close_outputs** -- if True, sends circushttpd stdout/stderr
to /dev/null. (default: False)
- **debug** -- if True, adds a lot of debug info in the stdout (default:
False)
- **proc_name** -- the arbiter process name
"""
def __init__(self, watchers, endpoint, pubsub_endpoint, check_delay=.5,
prereload_fn=None, context=None, loop=None, statsd=False,
stats_endpoint=None, statsd_close_outputs=False,
multicast_endpoint=None, plugins=None,
sockets=None, warmup_delay=0, httpd=False,
httpd_host='localhost', httpd_port=8080,
httpd_close_outputs=False, debug=False,
ssh_server=None, proc_name='circusd', pidfile=None,
loglevel=None, logoutput=None):
self.watchers = watchers
self.endpoint = endpoint
self.check_delay = check_delay
self.prereload_fn = prereload_fn
self.pubsub_endpoint = pubsub_endpoint
self.multicast_endpoint = multicast_endpoint
self.proc_name = proc_name
self.ssh_server = ssh_server
self.pidfile = pidfile
self.loglevel = loglevel
self.logoutput = logoutput
self.ctrl = self.loop = None
self.socket_event = False
# initialize zmq context
self._init_context(context)
self.pid = os.getpid()
self._watchers_names = {}
self.alive = True
self._lock = RLock()
self.debug = debug
if self.debug:
self.stdout_stream = self.stderr_stream = {'class': 'StdoutStream'}
else:
self.stdout_stream = self.stderr_stream = None
# initializing circusd-stats as a watcher when configured
self.statsd = statsd
self.stats_endpoint = stats_endpoint
if self.statsd:
cmd = "%s -c 'from circus import stats; stats.main()'" % \
sys.executable
cmd += ' --endpoint %s' % self.endpoint
cmd += ' --pubsub %s' % self.pubsub_endpoint
cmd += ' --statspoint %s' % self.stats_endpoint
if ssh_server is not None:
cmd += ' --ssh %s' % ssh_server
if debug:
cmd += ' --log-level DEBUG'
stats_watcher = Watcher('circusd-stats', cmd, use_sockets=True,
singleton=True,
stdout_stream=self.stdout_stream,
stderr_stream=self.stderr_stream,
copy_env=True, copy_path=True,
close_child_stderr=statsd_close_outputs,
close_child_stdout=statsd_close_outputs)
#.........这里部分代码省略.........
示例6: Arbiter
# 需要导入模块: from circus.controller import Controller [as 别名]
# 或者: from circus.controller.Controller import start [as 别名]
class Arbiter(object):
"""Class used to control a list of watchers.
Options:
- **watchers** -- a list of Watcher objects
- **endpoint** -- the controller ZMQ endpoint
- **pubsub_endpoint** -- the pubsub endpoint
- **check_delay** -- the delay between two controller points
(default: 1 s)
- **prereload_fn** -- callable that will be executed on each reload
(default: None)
- **context** -- if provided, the zmq context to reuse.
(default: None)
- **loop**: if provided, a :class:`zmq.eventloop.ioloop.IOLoop` instance
to reuse. (default: None)
- **check_flapping** -- when True, Circus will check for flapping
processes and automatically restart them. (default: True)
"""
def __init__(self,
watchers,
endpoint,
pubsub_endpoint,
check_delay=1.,
prereload_fn=None,
context=None,
loop=None,
check_flapping=True):
self.watchers = watchers
self.endpoint = endpoint
self.check_delay = check_delay
self.prereload_fn = prereload_fn
self.pubsub_endpoint = pubsub_endpoint
# initialize zmq context
self.context = context or zmq.Context.instance()
self.loop = loop or ioloop.IOLoop()
self.ctrl = Controller(endpoint, self.context, self.loop, self,
check_delay)
self.pid = os.getpid()
self._watchers_names = {}
self.alive = True
self.busy = False
self.check_flapping = check_flapping
@classmethod
def load_from_config(cls, config_file):
cfg = get_config(config_file)
# hack reload ioloop to use the monkey patched version
reload(ioloop)
watchers = []
for watcher in cfg.get('watchers', []):
watchers.append(Watcher.load_from_config(watcher))
# creating arbiter
arbiter = cls(
watchers,
cfg['endpoint'],
cfg['pubsub_endpoint'],
check_delay=cfg.get('check_delay', 1.),
prereload_fn=cfg.get('prereload_fn'))
return arbiter
@debuglog
def initialize(self):
# set process title
_setproctitle("circusd")
# event pub socket
self.evpub_socket = self.context.socket(zmq.PUB)
self.evpub_socket.bind(self.pubsub_endpoint)
self.evpub_socket.linger = 0
# initialize flapping
if self.check_flapping:
self.flapping = Flapping(self.context, self.endpoint,
self.pubsub_endpoint, self.check_delay)
# initialize watchers
for watcher in self.watchers:
self._watchers_names[watcher.name.lower()] = watcher
watcher.initialize(self.evpub_socket)
@debuglog
def start(self):
"""Starts all the watchers.
The start command is an infinite loop that waits
for any command from a client and that watches all the
processes and restarts them if needed.
"""
logger.info("Starting master on pid %s", self.pid)
self.initialize()
#.........这里部分代码省略.........