本文整理汇总了Python中service.Service方法的典型用法代码示例。如果您正苦于以下问题:Python service.Service方法的具体用法?Python service.Service怎么用?Python service.Service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service
的用法示例。
在下文中一共展示了service.Service方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def start(service):
"""
Start a service and wait until it's running.
"""
ok(service.start(block=TIMEOUT), 'Service failed to start')
assert_running()
return service
示例2: test_start
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_start(self):
"""
Test ``Service.start``.
"""
start(WaitingService())
示例3: test_start_timeout_ok
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_start_timeout_ok(self):
"""
Test ``Service.start`` with a timeout.
"""
ok(WaitingService().start(block=TIMEOUT))
示例4: test_start_timeout_fail
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_start_timeout_fail(self):
"""
Test ``Service.start`` with a timeout and a failing daemon.
"""
ok(not FailingService().start(block=0.1))
示例5: test_stop
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_stop(self):
"""
Test ``Service.stop``.
"""
start(WaitingService()).stop()
time.sleep(DELAY)
assert_not_running()
示例6: test_stop_timeout_fail
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_stop_timeout_fail(self):
"""
Test ``Service.stop`` with a timeout and stuck daemon.
"""
ok(not start(ForeverService()).stop(block=0.1))
示例7: test_kill
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_kill(self):
"""
Test ``Service.kill``.
"""
start(ForeverService()).kill()
time.sleep(DELAY)
assert_not_running()
示例8: test_kill_timeout_ok
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_kill_timeout_ok(self):
"""
Test ``Service.kill`` with a timeout.
"""
ok(start(ForeverService()).kill(block=TIMEOUT))
assert_not_running()
示例9: test_kill_timeout_fail
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_kill_timeout_fail(self):
"""
Test ``Service.kill`` with too short a timeout.
"""
os_kill = os.kill
def kill_mock(pid, sig):
if sig != signal.SIGKILL:
return os_kill(pid, sig)
with mock.patch('os.kill', side_effect=kill_mock):
ok(not start(ForeverService()).kill(block=0.1))
示例10: test_is_running
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def test_is_running(self):
"""
Test ``Service.is_running``.
"""
service = WaitingService()
ok(not service.is_running())
start(service)
ok(service.is_running())
示例11: run
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def run(self):
self.createConfig()
cmd = [ config.Config.CAP.haproxyBin, "-Ds", "-p", self.pidfile, "-f", self.cfgfile ]
if (os.path.isfile(self.pidfile)):
os.remove(self.pidfile)
os.chdir(self.dir)
log.A.audit(log.A.START, log.A.SERVICE, cmd=" ".join(cmd), serviceid=self.id)
if self.isClient():
if (config.Config.CAP.proxycStandalone):
command = cmd[0]
if config.Config.CAP.noRun:
log.L.warning("Exiting from dispatcher. Run manually:\n%s" % (" ".join(cmd)))
atexit.unregister(services.SERVICES.stop)
sys.exit()
else:
if not os.path.isfile(config.Config.CAP.haproxyBin):
log.L.error("Haproxy binary %s not found. Cannot continue!" % (config.Config.CAP.haproxyBin))
sys.exit(1)
log.L.warning("Running %s and exiting from dispatcher." % (" ".join(cmd)))
os.execv(command, cmd)
if not os.path.isfile(config.Config.CAP.haproxyBin):
log.L.error("Haproxy binary %s not found. Cannot continue!" % (config.Config.CAP.haproxyBin))
sys.exit(1)
self.process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, universal_newlines=True, shell=None)
self.pid = self.waitForPid()
log.L.info("Service %s: [pid=%s]" % (self.id, self.pid))
if self.isClient():
self.mgmtConnect("127.0.0.1", self.cfg["mgmtport"])
else:
self.mgmtConnect("socket", self.mgmtfile)
super().run()
示例12: setUp
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def setUp(self):
import cxxd_mocks, service
self.unsupported_request = 0xFF
self.payload = [0x1, 0x2, 0x3]
self.service = service.Service(cxxd_mocks.ServicePluginMock())
示例13: prefetch_models
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def prefetch_models():
models = ['bist', 'ner', 'intent_extraction']
for model in models:
services[model] = Service(model)
示例14: get_paragraphs
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def get_paragraphs():
if not services['machine_comprehension']:
services['machine_comprehension'] = Service('machine_comprehension')
return services['machine_comprehension'].get_paragraphs()
# pylint: disable=inconsistent-return-statements
示例15: inference
# 需要导入模块: import service [as 别名]
# 或者: from service import Service [as 别名]
def inference(request, body, response):
"""Makes an inference to a certain model"""
print(body)
if request.headers.get('CONTENT-TYPE') == 'application/gzip':
try:
original_data = gzip.decompress(request.stream.read())
input_docs = json.loads(str(original_data, 'utf-8'))["docs"]
model_name = json.loads(str(original_data, 'utf-8'))["model_name"]
except Exception:
response.status = hug.HTTP_500
return {'status': 'unexpected gzip error'}
elif request.headers.get('CONTENT-TYPE') == 'application/json':
if isinstance(body, str):
body = json.loads(body)
model_name = body.get('model_name')
input_docs = body.get('docs')
else:
response.status = status_codes.HTTP_400
return {'status': 'Content-Type header must be application/json or application/gzip'}
if not model_name:
response.status = status_codes.HTTP_400
return {'status': 'model_name is required'}
# If we've already initialized it, no use in reinitializing
if not services.get(model_name):
services[model_name] = Service(model_name)
if not isinstance(input_docs, list): # check if it's an array instead
response.status = status_codes.HTTP_400
return {'status': 'request not in proper format '}
headers = parse_headers(request.headers)
parsed_doc = services[model_name].get_service_inference(input_docs, headers)
resp_format = request.headers["RESPONSE-FORMAT"]
ret = format_response(resp_format, parsed_doc)
if request.headers.get('CONTENT-TYPE') == 'application/gzip':
response.content_type = resp_format
response.body = ret
# no return due to the fact that hug seems to assume json type upon return
else:
return ret