def test_reject_recursive_repeats_multithreaded(): @reject_recursive_repeats def recurse(sleep_now): time.sleep(sleep_now) try: recurse(0.05) return True except ValueError: return False thd1 = spawn(recurse, 0) thd2 = spawn(recurse, 0.02) assert thd2.get() and thd1.get()
def request_async(self, raw_method: str, raw_params: Any) -> UUID: request_id = uuid.uuid4() self.pending_requests[request_id] = spawn( self.request_blocking, raw_method=raw_method, raw_params=raw_params, ) return request_id
def test_spawning_simple_thread(): container = { 'success': None, } def target_fn(): container['success'] = True thread = spawn(target_fn) thread.join() assert container['success'] is True
def test_spawning_specific_thread_class(): container = { 'success': None, } def target_fn(): container['success'] = True thread = spawn(target_fn, thread_class=CustomThreadClass) thread.join() assert isinstance(thread, CustomThreadClass) assert container['success'] is True
def test_thread_with_return_value(): container = { 'success': None, } def target_fn(): container['success'] = True return 12345 thread = spawn(target_fn) thread.join() assert container['success'] is True assert thread.get() == 12345
def __init__(self, host="127.0.0.1", port=8545, *args, **kwargs): if not is_testrpc_available(): raise Exception("`TestRPCProvider` requires the `eth-testrpc` package to be installed") from testrpc.server import get_application application = get_application() self.server = make_server( host, port, application, ) self.thread = spawn(self.server.serve_forever) endpoint_uri = 'http://{0}:{1}'.format(host, port) super().__init__(endpoint_uri, *args, **kwargs)
def __init__(self, host="127.0.0.1", port=8545, *args, **kwargs): if not is_testrpc_available(): raise Exception( "`TestRPCProvider` requires the `eth-testrpc` package to be installed" ) from testrpc.server import get_application application = get_application() self.server = make_server( host, port, application, ) self.thread = spawn(self.server.serve_forever) endpoint_uri = 'http://{0}:{1}'.format(host, port) super().__init__(endpoint_uri, *args, **kwargs)