Python timeout_decorator.TimeoutError() Examples
The following are 8
code examples of timeout_decorator.TimeoutError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
timeout_decorator
, or try the search function
.
Example #1
Source File: GitWrapper.py From ngraph-onnx with Apache License 2.0 | 6 votes |
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
Example #2
Source File: utils.py From apm-integration-testing with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: api_wrapper_test.py From PokemonGo-Bot with MIT License | 5 votes |
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()
Example #4
Source File: test_migration_tool.py From indy-node with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: api_wrapper_test.py From PokemonGo-Bot-Backup with MIT License | 5 votes |
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()
Example #6
Source File: views.py From wharf with GNU Affero General Public License v3.0 | 5 votes |
def status(request): try: check_status() return HttpResponse("All good") except timeout_decorator.TimeoutError: return HttpResponseServerError("Timeout trying to get status")
Example #7
Source File: concurrent_requests.py From apm-integration-testing with Apache License 2.0 | 4 votes |
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)
Example #8
Source File: formatDetector.py From Zeratool with GNU General Public License v3.0 | 4 votes |
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