def test_load_virtualenv(self): watcher = mock.Mock() watcher.copy_env = False # we need the copy_env flag self.assertRaises(ValueError, load_virtualenv, watcher) watcher.copy_env = True watcher.virtualenv = 'XXX' # we want virtualenv to be a directory self.assertRaises(ValueError, load_virtualenv, watcher) watcher.virtualenv = self._create_dir() # we want virtualenv directory to contain a site-packages self.assertRaises(ValueError, load_virtualenv, watcher) py_ver = sys.version.split()[0][:3] site_pkg = os.path.join(watcher.virtualenv, 'lib', 'python%s' % py_ver, 'site-packages') os.makedirs(site_pkg) watcher.env = {} load_virtualenv(watcher) self.assertEqual(site_pkg, watcher.env['PYTHONPATH']) # test with a specific python version for the virtualenv site packages py_ver = "my_python_version" site_pkg = os.path.join(watcher.virtualenv, 'lib', 'python%s' % py_ver, 'site-packages') os.makedirs(site_pkg) watcher.env = {} load_virtualenv(watcher, py_ver=py_ver) self.assertEqual(site_pkg, watcher.env['PYTHONPATH'])
def test_load_virtualenv(self): watcher = mock.Mock() watcher.copy_env = False # we need the copy_env flag self.assertRaises(ValueError, load_virtualenv, watcher) watcher.copy_env = True watcher.virtualenv = 'XXX' # we want virtualenv to be a directory self.assertRaises(ValueError, load_virtualenv, watcher) watcher.virtualenv = self._create_dir() # we want virtualenv directory to contain a site-packages self.assertRaises(ValueError, load_virtualenv, watcher) py_ver = sys.version.split()[0][:3] site_pkg = os.path.join(watcher.virtualenv, 'lib', 'python%s' % py_ver, 'site-packages') os.makedirs(site_pkg) watcher.env = {} load_virtualenv(watcher) self.assertEqual(site_pkg, watcher.env['PYTHONPATH'])
def test_load_virtualenv(self): watcher = mock.Mock() watcher.copy_env = False # we need the copy_env flag self.assertRaises(ValueError, load_virtualenv, watcher) watcher.copy_env = True watcher.virtualenv = 'XXX' # we want virtualenv to be a directory self.assertRaises(ValueError, load_virtualenv, watcher) watcher.virtualenv = self._create_dir() # we want virtualenv directory to contain a site-packages self.assertRaises(ValueError, load_virtualenv, watcher) minor = sys.version_info[1] site_pkg = os.path.join(watcher.virtualenv, 'lib', 'python2.%s' % minor, 'site-packages') os.makedirs(site_pkg) watcher.env = {} load_virtualenv(watcher) self.assertEqual(site_pkg, watcher.env['PYTHONPATH'])
def test_load_virtualenv(self): watcher = mock.Mock() watcher.copy_env = False # we need the copy_env flag self.assertRaises(ValueError, load_virtualenv, watcher) watcher.copy_env = True watcher.virtualenv = 'XXX' # we want virtualenv to be a directory self.assertRaises(ValueError, load_virtualenv, watcher) watcher.virtualenv = self._create_dir() # we want virtualenv directory to contain a site-packages self.assertRaises(ValueError, load_virtualenv, watcher) py_ver = sys.version.split()[0][:3] site_pkg = os.path.join(watcher.virtualenv, 'lib', 'python%s' % py_ver, 'site-packages') os.makedirs(site_pkg) watcher.env = {} load_virtualenv(watcher) self.assertEqual(site_pkg, watcher.env['PYTHONPATH']) os.removedirs(site_pkg) # test with a specific python version for the virtualenv site packages py_ver = "my_python_version" site_pkg = os.path.join(watcher.virtualenv, 'lib', 'python%s' % py_ver, 'site-packages') os.makedirs(site_pkg) watcher.env = {} load_virtualenv(watcher, py_ver=py_ver) self.assertEqual(site_pkg, watcher.env['PYTHONPATH']) os.removedirs(site_pkg) # test with a pypy virtual environment watcher.env = {} py_ver = sys.version.split()[0][:3] site_pkg_pypy = os.path.join(watcher.virtualenv, 'lib', 'pypy%s' % py_ver, 'site-packages') os.makedirs(site_pkg_pypy) load_virtualenv(watcher, py_ver=py_ver) self.assertEqual(site_pkg_pypy, watcher.env['PYTHONPATH']) os.removedirs(site_pkg_pypy)
def __init__(self, name, cmd, args=None, numprocesses=1, warmup_delay=0., working_dir=None, shell=False, shell_args=None, uid=None, max_retry=5, gid=None, send_hup=False, stop_signal=signal.SIGTERM, stop_children=False, env=None, graceful_timeout=30.0, prereload_fn=None, rlimits=None, executable=None, stdout_stream=None, stderr_stream=None, priority=0, loop=None, singleton=False, use_sockets=False, copy_env=False, copy_path=False, max_age=0, max_age_variance=30, hooks=None, respawn=True, autostart=True, on_demand=False, virtualenv=None, stdin_socket=None, close_child_stdin=True, close_child_stdout=False, close_child_stderr=False, virtualenv_py_ver=None, use_papa=False, **options): self.name = name self.use_sockets = use_sockets self.on_demand = on_demand self.res_name = name.lower().replace(" ", "_") self.numprocesses = int(numprocesses) self.warmup_delay = warmup_delay self.cmd = cmd self.args = args self._status = "stopped" self.graceful_timeout = float(graceful_timeout) self.prereload_fn = prereload_fn self.executable = None self.priority = priority self.stdout_stream_conf = copy.copy(stdout_stream) self.stderr_stream_conf = copy.copy(stderr_stream) self.stdout_stream = get_stream(self.stdout_stream_conf) self.stderr_stream = get_stream(self.stderr_stream_conf) self.stream_redirector = None self.max_retry = int(max_retry) self._options = options self.singleton = singleton self.copy_env = copy_env self.copy_path = copy_path self.virtualenv = virtualenv self.virtualenv_py_ver = virtualenv_py_ver self.max_age = int(max_age) self.max_age_variance = int(max_age_variance) self.ignore_hook_failure = [ 'before_stop', 'after_stop', 'before_signal', 'after_signal', 'extended_stats' ] self.respawn = respawn self.autostart = autostart self.stdin_socket = stdin_socket self.close_child_stdin = close_child_stdin self.close_child_stdout = close_child_stdout self.close_child_stderr = close_child_stderr self.use_papa = use_papa and papa is not None self.loop = loop or ioloop.IOLoop.instance() if singleton and self.numprocesses not in (0, 1): raise ValueError("Cannot have %d processes with a singleton " " watcher" % self.numprocesses) if IS_WINDOWS: if self.stdout_stream or self.stderr_stream: raise NotImplementedError("Streams are not supported" " on Windows.") if not copy_env and not env: # Copy the env by default on Windows as we can't run any # executable without some env variables # Eventually, we could set only some required variables, # such as SystemRoot self.copy_env = True self.optnames = ( ("numprocesses", "warmup_delay", "working_dir", "uid", "gid", "send_hup", "stop_signal", "stop_children", "shell", "shell_args", "env", "max_retry", "cmd", "args", "respawn", "graceful_timeout", "executable", "use_sockets", "priority", "copy_env", "singleton", "stdout_stream_conf", "on_demand", "stderr_stream_conf", "max_age", "max_age_variance", "close_child_stdin", "close_child_stdout", "close_child_stderr", "use_papa") + tuple(options.keys())) if not working_dir: # working dir hasn't been set working_dir = util.get_working_dir() self.working_dir = working_dir self.processes = {} self.shell = shell self.shell_args = shell_args self.uid = uid self.gid = gid if self.copy_env: self.env = os.environ.copy() if self.copy_path: path = os.pathsep.join(sys.path) self.env['PYTHONPATH'] = path if env is not None: self.env.update(env) else: if self.copy_path: raise ValueError(('copy_env and copy_path must have the ' 'same value')) self.env = env if self.virtualenv: util.load_virtualenv(self, py_ver=virtualenv_py_ver) # load directories in PYTHONPATH if provided # so if a hook is there, it can be loaded if self.env is not None and 'PYTHONPATH' in self.env: for path in self.env['PYTHONPATH'].split(os.pathsep): if path in sys.path: continue site.addsitedir(path) self.rlimits = rlimits self.send_hup = send_hup self.stop_signal = stop_signal self.stop_children = stop_children self.sockets = self.evpub_socket = None self.arbiter = None self.hooks = {} self._resolve_hooks(hooks) self._found_wids = [] if self.use_papa: with papa.Papa() as p: base_name = 'circus.{0}.*'.format(name.lower()) running = p.list_processes(base_name) self._found_wids = [ int(proc_name[len(base_name) - 1:]) for proc_name in running ]
def __init__(self, name, cmd, args=None, numprocesses=1, warmup_delay=0., working_dir=None, shell=False, shell_args=None, uid=None, max_retry=5, gid=None, send_hup=False, stop_signal=signal.SIGTERM, stop_children=False, env=None, graceful_timeout=30.0, prereload_fn=None, rlimits=None, executable=None, stdout_stream=None, stderr_stream=None, priority=0, loop=None, singleton=False, use_sockets=False, copy_env=False, copy_path=False, max_age=0, max_age_variance=30, hooks=None, respawn=True, autostart=True, on_demand=False, virtualenv=None, stdin_socket=None, close_child_stdin=True, close_child_stdout=False, close_child_stderr=False, virtualenv_py_ver=None, use_papa=False, **options): self.name = name self.use_sockets = use_sockets self.on_demand = on_demand self.res_name = name.lower().replace(" ", "_") self.numprocesses = int(numprocesses) self.warmup_delay = warmup_delay self.cmd = cmd self.args = args self._status = "stopped" self.graceful_timeout = float(graceful_timeout) self.prereload_fn = prereload_fn self.executable = None self.priority = priority self.stdout_stream_conf = copy.copy(stdout_stream) self.stderr_stream_conf = copy.copy(stderr_stream) self.stdout_stream = get_stream(self.stdout_stream_conf) self.stderr_stream = get_stream(self.stderr_stream_conf) self.stream_redirector = None self.max_retry = int(max_retry) self._options = options self.singleton = singleton self.copy_env = copy_env self.copy_path = copy_path self.virtualenv = virtualenv self.virtualenv_py_ver = virtualenv_py_ver self.max_age = int(max_age) self.max_age_variance = int(max_age_variance) self.ignore_hook_failure = ['before_stop', 'after_stop', 'before_signal', 'after_signal', 'extended_stats'] self.respawn = respawn self.autostart = autostart self.stdin_socket = stdin_socket self.close_child_stdin = close_child_stdin self.close_child_stdout = close_child_stdout self.close_child_stderr = close_child_stderr self.use_papa = use_papa and papa is not None self.loop = loop or ioloop.IOLoop.instance() if singleton and self.numprocesses not in (0, 1): raise ValueError("Cannot have %d processes with a singleton " " watcher" % self.numprocesses) if IS_WINDOWS: if self.stdout_stream or self.stderr_stream: raise NotImplementedError("Streams are not supported" " on Windows.") if not copy_env and not env: # Copy the env by default on Windows as we can't run any # executable without some env variables # Eventually, we could set only some required variables, # such as SystemRoot self.copy_env = True self.optnames = (("numprocesses", "warmup_delay", "working_dir", "uid", "gid", "send_hup", "stop_signal", "stop_children", "shell", "shell_args", "env", "max_retry", "cmd", "args", "respawn", "graceful_timeout", "executable", "use_sockets", "priority", "copy_env", "singleton", "stdout_stream_conf", "on_demand", "stderr_stream_conf", "max_age", "max_age_variance", "close_child_stdin", "close_child_stdout", "close_child_stderr", "use_papa") + tuple(options.keys())) if not working_dir: # working dir hasn't been set working_dir = util.get_working_dir() self.working_dir = working_dir self.processes = {} self.shell = shell self.shell_args = shell_args self.uid = uid self.gid = gid if self.copy_env: self.env = os.environ.copy() if self.copy_path: path = os.pathsep.join(sys.path) self.env['PYTHONPATH'] = path if env is not None: self.env.update(env) else: if self.copy_path: raise ValueError(('copy_env and copy_path must have the ' 'same value')) self.env = env if self.virtualenv: util.load_virtualenv(self, py_ver=virtualenv_py_ver) # load directories in PYTHONPATH if provided # so if a hook is there, it can be loaded if self.env is not None and 'PYTHONPATH' in self.env: for path in self.env['PYTHONPATH'].split(os.pathsep): if path in sys.path: continue site.addsitedir(path) self.rlimits = rlimits self.send_hup = send_hup self.stop_signal = stop_signal self.stop_children = stop_children self.sockets = self.evpub_socket = None self.arbiter = None self.hooks = {} self._resolve_hooks(hooks) self._found_wids = [] if self.use_papa: with papa.Papa() as p: base_name = 'circus.{0}.*'.format(name.lower()) running = p.list_processes(base_name) self._found_wids = [int(proc_name[len(base_name) - 1:]) for proc_name in running]
def __init__(self, name, cmd, args=None, numprocesses=1, warmup_delay=0., working_dir=None, shell=False, uid=None, max_retry=5, gid=None, send_hup=False, env=None, stopped=True, graceful_timeout=30., prereload_fn=None, rlimits=None, executable=None, stdout_stream=None, stderr_stream=None, priority=0, loop=None, singleton=False, use_sockets=False, copy_env=False, copy_path=False, max_age=0, max_age_variance=30, hooks=None, respawn=True, autostart=True, on_demand=False, virtualenv=None, close_child_stdout=False, close_child_stderr=False, **options): self.name = name self.use_sockets = use_sockets self.on_demand = on_demand self.res_name = name.lower().replace(" ", "_") self.numprocesses = int(numprocesses) self.warmup_delay = warmup_delay self.cmd = cmd self.args = args self._process_counter = 0 self.stopped = stopped self.graceful_timeout = float(graceful_timeout) self.prereload_fn = prereload_fn self.executable = None self.priority = priority self.stdout_stream_conf = copy.copy(stdout_stream) self.stderr_stream_conf = copy.copy(stderr_stream) self.stdout_stream = get_stream(self.stdout_stream_conf) self.stderr_stream = get_stream(self.stderr_stream_conf) self.stdout_redirector = self.stderr_redirector = None self.max_retry = max_retry self._options = options self.singleton = singleton self.copy_env = copy_env self.copy_path = copy_path self.virtualenv = virtualenv self.max_age = int(max_age) self.max_age_variance = int(max_age_variance) self.ignore_hook_failure = ['before_stop', 'after_stop'] self.hooks = self._resolve_hooks(hooks) self.respawn = respawn self.autostart = autostart self.close_child_stdout = close_child_stdout self.close_child_stderr = close_child_stderr self.loop = loop or ioloop.IOLoop.instance() if singleton and self.numprocesses not in (0, 1): raise ValueError("Cannot have %d processes with a singleton " " watcher" % self.numprocesses) self.optnames = ( ("numprocesses", "warmup_delay", "working_dir", "uid", "gid", "send_hup", "shell", "env", "max_retry", "cmd", "args", "graceful_timeout", "executable", "use_sockets", "priority", "copy_env", "singleton", "stdout_stream_conf", "on_demand", "stderr_stream_conf", "max_age", "max_age_variance", "close_child_stdout", "close_child_stderr") + tuple(options.keys())) if not working_dir: # working dir hasn't been set working_dir = util.get_working_dir() self.working_dir = working_dir self.processes = {} self.shell = shell self.uid = uid self.gid = gid if self.copy_env: self.env = os.environ.copy() if self.copy_path: path = os.pathsep.join(sys.path) self.env['PYTHONPATH'] = path if env is not None: self.env.update(env) else: if self.copy_path: raise ValueError(('copy_env and copy_path must have the ' 'same value')) self.env = env if self.virtualenv: util.load_virtualenv(self) self.rlimits = rlimits self.send_hup = send_hup self.sockets = self.evpub_socket = None self.arbiter = None
def __init__(self, name, cmd, args=None, numprocesses=1, warmup_delay=0., working_dir=None, shell=False, uid=None, max_retry=5, gid=None, send_hup=False, env=None, stopped=True, graceful_timeout=30., prereload_fn=None, rlimits=None, executable=None, stdout_stream=None, stderr_stream=None, priority=0, loop=None, singleton=False, use_sockets=False, copy_env=False, copy_path=False, max_age=0, max_age_variance=30, hooks=None, respawn=True, autostart=True, on_demand=False, virtualenv=None, **options): self.name = name self.use_sockets = use_sockets self.on_demand = on_demand self.res_name = name.lower().replace(" ", "_") self.numprocesses = int(numprocesses) self.warmup_delay = warmup_delay self.cmd = cmd self.args = args self._process_counter = 0 self.stopped = stopped self.graceful_timeout = float(graceful_timeout) self.prereload_fn = prereload_fn self.executable = None self.priority = priority self.stdout_stream_conf = copy.copy(stdout_stream) self.stderr_stream_conf = copy.copy(stderr_stream) self.stdout_stream = get_stream(self.stdout_stream_conf) self.stderr_stream = get_stream(self.stderr_stream_conf) self.stdout_redirector = self.stderr_redirector = None self.max_retry = max_retry self._options = options self.singleton = singleton self.copy_env = copy_env self.copy_path = copy_path self.virtualenv = virtualenv self.max_age = int(max_age) self.max_age_variance = int(max_age_variance) self.ignore_hook_failure = ['before_stop', 'after_stop'] self.hooks = self._resolve_hooks(hooks) self.respawn = respawn self.autostart = autostart self.loop = loop or ioloop.IOLoop.instance() if singleton and self.numprocesses not in (0, 1): raise ValueError("Cannot have %d processes with a singleton " " watcher" % self.numprocesses) self.optnames = (("numprocesses", "warmup_delay", "working_dir", "uid", "gid", "send_hup", "shell", "env", "max_retry", "cmd", "args", "graceful_timeout", "executable", "use_sockets", "priority", "copy_env", "singleton", "stdout_stream_conf", "on_demand", "stderr_stream_conf", "max_age", "max_age_variance") + tuple(options.keys())) if not working_dir: # working dir hasn't been set working_dir = util.get_working_dir() self.working_dir = working_dir self.processes = {} self.shell = shell self.uid = uid self.gid = gid if self.copy_env: self.env = os.environ.copy() if self.copy_path: path = os.pathsep.join(sys.path) self.env['PYTHONPATH'] = path if env is not None: self.env.update(env) else: if self.copy_path: raise ValueError(('copy_env and copy_path must have the ' 'same value')) self.env = env if self.virtualenv: util.load_virtualenv(self) self.rlimits = rlimits self.send_hup = send_hup self.sockets = self.evpub_socket = None self.arbiter = None