本文整理匯總了Python中timeout_decorator.TimeoutError方法的典型用法代碼示例。如果您正苦於以下問題:Python timeout_decorator.TimeoutError方法的具體用法?Python timeout_decorator.TimeoutError怎麽用?Python timeout_decorator.TimeoutError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類timeout_decorator
的用法示例。
在下文中一共展示了timeout_decorator.TimeoutError方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_git_time
# 需要導入模塊: import timeout_decorator [as 別名]
# 或者: from timeout_decorator import TimeoutError [as 別名]
def get_git_time(self):
"""Retrieve time from GitHub.
Used to reliably determine time during Watchdog run.
:return: Datetime object describing current time
:rtype: datetime
"""
try:
datetime_object = self._get_git_time()
except ValueError as e:
raise GitWrapperError(str(e))
except GithubException as e:
message = 'GitHub Exception during API status retrieval. Exception: {}'.format(str(e))
raise GitWrapperError(message)
except timeout_decorator.TimeoutError:
message = 'GitHub Exception during API status retrieval. Timeout during API request.'
raise GitWrapperError(message)
return datetime_object
示例2: check_elasticsearch_count
# 需要導入模塊: import timeout_decorator [as 別名]
# 或者: from timeout_decorator import TimeoutError [as 別名]
def check_elasticsearch_count(elasticsearch,
expected,
processor='transaction',
query=None):
if query is None:
query = {'query': {'term': {'processor.name': processor}}}
actual = 0
retries = 0
max_retries = 3
while actual != expected and retries < max_retries:
try:
actual = elasticsearch.count(query)
retries += 1
time.sleep(10)
except TimeoutError:
retries += 1
actual = -1
assert actual == expected, "Expected {}, queried {}".format(
expected, actual)
示例3: test_api_call_throttle_should_fail
# 需要導入模塊: import timeout_decorator [as 別名]
# 或者: from timeout_decorator import TimeoutError [as 別名]
def test_api_call_throttle_should_fail(self):
request = FakeApi().create_request()
request.is_response_valid = MagicMock(return_value=True)
request.requests_per_seconds = 5
with self.assertRaises(TimeoutError):
for i in range(request.requests_per_seconds * 2):
request.call()
示例4: testMigrateTimesOut
# 需要導入模塊: import timeout_decorator [as 別名]
# 或者: from timeout_decorator import TimeoutError [as 別名]
def testMigrateTimesOut(monkeypatch):
monkeypatch.setattr(migration_tool, '_call_migration_script',
lambda *x: exec('raise(TimeoutError())'))
monkeypatch.setattr(migration_tool, '_get_migration_scripts',
lambda *x: TEST_MIGRATION_SCRIPTS)
with pytest.raises(TimeoutError):
migration_tool.migrate(TEST_VERSION, TEST_NEW_VERSION, TEST_TIMEOUT)
示例5: status
# 需要導入模塊: import timeout_decorator [as 別名]
# 或者: from timeout_decorator import TimeoutError [as 別名]
def status(request):
try:
check_status()
return HttpResponse("All good")
except timeout_decorator.TimeoutError:
return HttpResponseServerError("Timeout trying to get status")
示例6: check_counts
# 需要導入模塊: import timeout_decorator [as 別名]
# 或者: from timeout_decorator import TimeoutError [as 別名]
def check_counts(self, it, max_wait=60, backoff=1):
err = "queried for {}, expected {}, got {}"
def assert_count(terms, expected):
"""wait a bit for doc count to reach expectation"""
@timeout_decorator.timeout(max_wait)
def check_count(mut_actual):
while True:
rsp = self.es.count(index=self.index, body=self.elasticsearch.term_q(terms))
mut_actual[0] = rsp["count"]
if mut_actual[0] >= expected:
return
time.sleep(backoff)
mut_actual = [-1] # keep actual count in this mutable
try:
check_count(mut_actual)
except timeout_decorator.TimeoutError:
pass
actual = mut_actual[0]
assert actual == expected, err.format(terms, expected, actual)
self.es.indices.refresh()
service_names = [ep.app_name for ep in self.endpoints]
transactions_count = self.count("transaction") * it
assert_count([("processor.event", "transaction"), ("service.name", service_names)], transactions_count)
spans_count = self.count("span") * it
assert_count([("processor.event", "span"), ('service.name', service_names)], spans_count)
transactions_sum = spans_sum = 0
for ep in self.endpoints:
for span_name in ep.span_names:
count = ep.count("span") * it / len(ep.span_names)
spans_sum += count
assert_count([
("processor.event", "span"),
("span.name", span_name),
("service.name", ep.app_name),
], count)
count = ep.count("transaction") * it
transactions_sum += count
assert_count([
("processor.event", "transaction"),
("service.name", ep.app_name),
("transaction.name", ep.transaction_name),
], count)
assert transactions_count == transactions_sum, err.format(
"transactions all endpoints", transactions_count, transactions_sum)
assert spans_count == spans_sum, err.format(
"spans all endpoints", spans_count, spans_sum)
示例7: checkFormat
# 需要導入模塊: import timeout_decorator [as 別名]
# 或者: from timeout_decorator import TimeoutError [as 別名]
def checkFormat(binary_name,inputType="STDIN"):
p = angr.Project(binary_name,load_options={"auto_load_libs": False})
p.hook_symbol('printf',printFormat)
#Setup state based on input type
argv = [binary_name]
if inputType == "STDIN":
state = p.factory.full_init_state(args=argv)
elif inputType == "LIBPWNABLE":
handle_connection = p.loader.main_object.get_symbol('handle_connection')
state = p.factory.entry_state(addr=handle_connection.rebased_addr)
else:
arg = claripy.BVS("arg1", 300 * 8)
argv.append(arg)
state = p.factory.full_init_state(args=argv)
state.globals['arg'] = arg
state.globals['inputType'] = inputType
simgr = p.factory.simgr(state, immutable=False, save_unconstrained=True)
run_environ = {}
run_environ['type'] = None
end_state = None
#Lame way to do a timeout
try:
@timeout_decorator.timeout(120)
def exploreBinary(simgr):
simgr.explore(find=lambda s: 'type' in s.globals)
exploreBinary(simgr)
if 'found' in simgr.stashes and len(simgr.found):
end_state = simgr.found[0]
run_environ['type'] = end_state.globals['type']
run_environ['position'] = end_state.globals['position']
run_environ['length'] = end_state.globals['length']
except (KeyboardInterrupt, timeout_decorator.TimeoutError) as e:
print("[~] Format check timed out")
if (inputType == "STDIN" or inputType == "LIBPWNABLE")and end_state is not None:
stdin_str = str(end_state.posix.dumps(0))
print("[+] Triggerable with STDIN : {}".format(stdin_str))
run_environ['input'] = stdin_str
elif inputType == "ARG" and end_state is not None:
arg_str = str(end_state.solver.eval(arg,cast_to=str))
run_environ['input'] = arg_str
print("[+] Triggerable with arg : {}".format(arg_str))
return run_environ