本文整理汇总了Python中circus.sockets.CircusSocket类的典型用法代码示例。如果您正苦于以下问题:Python CircusSocket类的具体用法?Python CircusSocket怎么用?Python CircusSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CircusSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_socket
def test_socket(self):
if TRAVIS:
return
sock = CircusSocket('somename', 'localhost', 0)
try:
sock.bind_and_listen()
finally:
sock.close()
示例2: test_unix_socket
def test_unix_socket(self):
sockfile = self._get_tmp_filename()
sock = CircusSocket('somename', path=sockfile, umask=0)
try:
sock.bind_and_listen()
self.assertTrue(os.path.exists(sockfile))
permissions = oct(os.stat(sockfile).st_mode)[-3:]
self.assertEqual(permissions, '777')
finally:
sock.close()
示例3: test_unix_socket
def test_unix_socket(self):
fd, sockfile = tempfile.mkstemp()
os.close(fd)
os.remove(sockfile)
sock = CircusSocket('somename', path=sockfile)
try:
sock.bind_and_listen()
self.assertTrue(os.path.exists(sockfile))
finally:
sock.close()
os.remove(sockfile)
示例4: test_unix_socket
def test_unix_socket(self):
fd, sockfile = tempfile.mkstemp()
os.close(fd)
os.remove(sockfile)
sock = CircusSocket('somename', path=sockfile, umask=0)
try:
sock.bind_and_listen()
self.assertTrue(os.path.exists(sockfile))
permissions = oct(os.stat(sockfile).st_mode)[-3:]
self.assertEqual(permissions, '777')
finally:
sock.close()
示例5: load_from_config
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))
sockets = []
for socket in cfg.get('sockets', []):
sockets.append(CircusSocket.load_from_config(socket))
# 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'),
plugins=cfg.get('plugins'), sockets=sockets,
warmup_delay=cfg.get('warmup_delay', 0),
httpd=cfg.get('httpd', False),
httpd_host=cfg.get('httpd_host', 'localhost'),
httpd_port=cfg.get('httpd_port', 8080))
return arbiter
示例6: test_issue310
def test_issue310(self):
'''
https://github.com/mozilla-services/circus/pull/310
Allow $(circus.sockets.name) to be used in args.
'''
conf = get_config(_CONF['issue310'])
watcher = Watcher.load_from_config(conf['watchers'][0])
socket = CircusSocket.load_from_config(conf['sockets'][0])
try:
watcher.initialize(None, {'web': socket}, None)
process = Process(watcher._nextwid, watcher.cmd,
args=watcher.args,
working_dir=watcher.working_dir,
shell=watcher.shell, uid=watcher.uid,
gid=watcher.gid, env=watcher.env,
rlimits=watcher.rlimits, spawn=False,
executable=watcher.executable,
use_fds=watcher.use_sockets,
watcher=watcher)
sockets_fds = watcher._get_sockets_fds()
formatted_args = process.format_args(sockets_fds=sockets_fds)
fd = sockets_fds['web']
self.assertEqual(formatted_args,
['foo', '--fd', str(fd)])
finally:
socket.close()
示例7: test_issue310
def test_issue310(self):
"""
https://github.com/mozilla-services/circus/pull/310
Allow $(circus.sockets.name) to be used in args.
"""
conf = get_config(_CONF["issue310"])
watcher = Watcher.load_from_config(conf["watchers"][0])
socket = CircusSocket.load_from_config(conf["sockets"][0])
watcher.initialize(None, {"web": socket}, None)
process = Process(
watcher._process_counter,
watcher.cmd,
args=watcher.args,
working_dir=watcher.working_dir,
shell=watcher.shell,
uid=watcher.uid,
gid=watcher.gid,
env=watcher.env,
rlimits=watcher.rlimits,
spawn=False,
executable=watcher.executable,
use_fds=watcher.use_sockets,
watcher=watcher,
)
fd = watcher._get_sockets_fds()["web"]
formatted_args = process.format_args()
self.assertEquals(formatted_args, ["foo", "--fd", str(fd)])
示例8: load_from_config
def load_from_config(cls, config_file):
cfg = get_config(config_file)
watchers = []
for watcher in cfg.get('watchers', []):
watchers.append(Watcher.load_from_config(watcher))
sockets = []
for socket in cfg.get('sockets', []):
sockets.append(CircusSocket.load_from_config(socket))
# 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'),
plugins=cfg.get('plugins'), sockets=sockets,
warmup_delay=cfg.get('warmup_delay', 0),
httpd=cfg.get('httpd', False),
httpd_host=cfg.get('httpd_host', 'localhost'),
httpd_port=cfg.get('httpd_port', 8080),
debug=cfg.get('debug', False),
stream_backend=cfg.get('stream_backend', 'thread'),
ssh_server=cfg.get('ssh_server', None))
return arbiter
示例9: load_from_config
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))
sockets = []
for socket in cfg.get("sockets", []):
sockets.append(CircusSocket.load_from_config(socket))
# creating arbiter
arbiter = cls(
watchers,
cfg["endpoint"],
cfg["pubsub_endpoint"],
check_delay=cfg.get("check_delay", 1.0),
prereload_fn=cfg.get("prereload_fn"),
stats_endpoint=cfg.get("stats_endpoint"),
plugins=cfg.get("plugins"),
sockets=sockets,
)
return arbiter
示例10: _get_sockets_fds
def _get_sockets_fds(self):
"""Returns sockets dict. If this worker's cmd indicates use of
a SO_REUSEPORT socket, a new socket is created and bound. This
new socket's FD replaces original socket's FD in returned dict.
This method populates `self._sockets` list. This list should be
let go after `fork()`.
"""
sockets_fds = None
if self.watcher is not None and self.watcher.sockets is not None:
sockets_fds = self.watcher._get_sockets_fds()
reuseport_sockets = tuple((sn, s) for (sn, s)
in self.watcher.sockets.items()
if s.so_reuseport)
for sn, s in reuseport_sockets:
# watcher.cmd uses this reuseport socket
if 'circus.sockets.%s' % sn in self.watcher.cmd:
sock = CircusSocket.load_from_config(s._cfg)
sock.bind_and_listen()
# replace original socket's fd
sockets_fds[sn] = sock.fileno()
# keep new socket until fork returns
self._sockets.append(sock)
return sockets_fds
示例11: load_from_config
def load_from_config(cls, config_file):
cfg = get_config(config_file)
watchers = []
for watcher in cfg.get('watchers', []):
watchers.append(Watcher.load_from_config(watcher))
sockets = []
for socket in cfg.get('sockets', []):
sockets.append(CircusSocket.load_from_config(socket))
httpd = cfg.get('httpd', False)
if httpd:
# controlling that we have what it takes to run the web UI
# if something is missing this will tell the user
try:
import circusweb # NOQA
except ImportError:
logger.error('You need to install circus-web')
sys.exit(1)
# 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'),
plugins=cfg.get('plugins'), sockets=sockets,
warmup_delay=cfg.get('warmup_delay', 0),
httpd=httpd,
httpd_host=cfg.get('httpd_host', 'localhost'),
httpd_port=cfg.get('httpd_port', 8080),
debug=cfg.get('debug', False),
ssh_server=cfg.get('ssh_server', None))
return arbiter
示例12: test_load_from_config_blocking
def test_load_from_config_blocking(self):
# test default to false
config = {'name': 'somename', 'host': 'localhost', 'port': 0}
sock = CircusSocket.load_from_config(config)
self.assertEqual(sock.blocking, False)
sock.bind_and_listen()
self.assertTrue(is_nonblock(sock.fileno()))
sock.close()
# test when true
config = {'name': 'somename', 'host': 'localhost', 'port': 0,
'blocking': True}
sock = CircusSocket.load_from_config(config)
self.assertEqual(sock.blocking, True)
sock.bind_and_listen()
self.assertFalse(is_nonblock(sock.fileno()))
sock.close()
示例13: test_load_from_config_umask
def test_load_from_config_umask(self):
sockfile = self._get_tmp_filename()
config = {"name": "somename", "path": sockfile, "umask": 0}
sock = CircusSocket.load_from_config(config)
try:
self.assertEqual(sock.umask, 0)
finally:
sock.close()
示例14: test_reuseport_supported
def test_reuseport_supported(self):
config = {"name": "", "host": "localhost", "port": 0, "so_reuseport": True}
sock = CircusSocket.load_from_config(config)
sockopt = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT)
self.assertEqual(sock.so_reuseport, True)
self.assertNotEqual(sockopt, 0)
示例15: test_load_from_config_replace
def test_load_from_config_replace(self):
sockfile = self._get_file()
config = {'name': 'somename', 'path': sockfile, 'replace': False}
sock = CircusSocket.load_from_config(config)
try:
self.assertRaises(OSError, sock.bind_and_listen)
finally:
sock.close()
config = {'name': 'somename', 'path': sockfile, 'replace': True}
sock = CircusSocket.load_from_config(config)
sock.bind_and_listen()
try:
self.assertEqual(sock.replace, True)
finally:
sock.close()