當前位置: 首頁>>代碼示例>>Python>>正文


Python service.Service方法代碼示例

本文整理匯總了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 
開發者ID:torfsen,項目名稱:service,代碼行數:9,代碼來源:test_service.py

示例2: test_start

# 需要導入模塊: import service [as 別名]
# 或者: from service import Service [as 別名]
def test_start(self):
        """
        Test ``Service.start``.
        """
        start(WaitingService()) 
開發者ID:torfsen,項目名稱:service,代碼行數:7,代碼來源:test_service.py

示例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)) 
開發者ID:torfsen,項目名稱:service,代碼行數:7,代碼來源:test_service.py

示例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)) 
開發者ID:torfsen,項目名稱:service,代碼行數:7,代碼來源:test_service.py

示例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() 
開發者ID:torfsen,項目名稱:service,代碼行數:9,代碼來源:test_service.py

示例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)) 
開發者ID:torfsen,項目名稱:service,代碼行數:7,代碼來源:test_service.py

示例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() 
開發者ID:torfsen,項目名稱:service,代碼行數:9,代碼來源:test_service.py

示例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() 
開發者ID:torfsen,項目名稱:service,代碼行數:8,代碼來源:test_service.py

示例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)) 
開發者ID:torfsen,項目名稱:service,代碼行數:14,代碼來源:test_service.py

示例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()) 
開發者ID:torfsen,項目名稱:service,代碼行數:10,代碼來源:test_service.py

示例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() 
開發者ID:LetheanMovement,項目名稱:lethean-vpn,代碼行數:33,代碼來源:service_ha.py

示例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()) 
開發者ID:JBakamovic,項目名稱:cxxd,代碼行數:7,代碼來源:test_service.py

示例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) 
開發者ID:NervanaSystems,項目名稱:nlp-architect,代碼行數:6,代碼來源:serve.py

示例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 
開發者ID:NervanaSystems,項目名稱:nlp-architect,代碼行數:9,代碼來源:serve.py

示例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 
開發者ID:NervanaSystems,項目名稱:nlp-architect,代碼行數:40,代碼來源:serve.py


注:本文中的service.Service方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。