Python eventlet.sleep() Examples
The following are 30
code examples of eventlet.sleep().
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
eventlet
, or try the search function
.
Example #1
Source File: test_wiring_inquiry.py From st2 with Apache License 2.0 | 6 votes |
def test_parallel_inquiries(self): # Launch the workflow. The workflow will paused at the pending task. ex = self._execute_workflow('examples.orquesta-ask-parallel') ex = self._wait_for_state(ex, ac_const.LIVEACTION_STATUS_PAUSED) # Respond to the first inquiry. t1_ac_exs = self._wait_for_task(ex, 'ask_jack', ac_const.LIVEACTION_STATUS_PENDING) self.st2client.inquiries.respond(t1_ac_exs[0].id, {'approved': True}) t1_ac_exs = self._wait_for_task(ex, 'ask_jack', ac_const.LIVEACTION_STATUS_SUCCEEDED) # Allow some time for the first inquiry to get processed. eventlet.sleep(1) # Respond to the second inquiry. t2_ac_exs = self._wait_for_task(ex, 'ask_jill', ac_const.LIVEACTION_STATUS_PENDING) self.st2client.inquiries.respond(t2_ac_exs[0].id, {'approved': True}) t2_ac_exs = self._wait_for_task(ex, 'ask_jill', ac_const.LIVEACTION_STATUS_SUCCEEDED) # Wait for completion. ex = self._wait_for_state(ex, ac_const.LIVEACTION_STATUS_SUCCEEDED)
Example #2
Source File: test_service_setup_log_level_filtering.py From st2 with Apache License 2.0 | 6 votes |
def test_kombu_heartbeat_tick_log_messages_are_excluded(self): # 1. system.debug = True config option is set, verify heartbeat_tick message is not logged process = self._start_process(config_path=ST2_CONFIG_SYSTEM_LL_DEBUG_PATH) self.add_process(process=process) # Give it some time to start up eventlet.sleep(5) process.send_signal(signal.SIGKILL) stdout = '\n'.join(process.stdout.read().decode('utf-8').split('\n')) self.assertNotIn('heartbeat_tick', stdout) # 2. system.debug = False, log level is set to debug process = self._start_process(config_path=ST2_CONFIG_DEBUG_LL_PATH) self.add_process(process=process) # Give it some time to start up eventlet.sleep(5) process.send_signal(signal.SIGKILL) stdout = '\n'.join(process.stdout.read().decode('utf-8').split('\n')) self.assertNotIn('heartbeat_tick', stdout)
Example #3
Source File: geventlet.py From jbox with MIT License | 6 votes |
def run(self): acceptors = [] for sock in self.sockets: gsock = GreenSocket(sock) gsock.setblocking(1) hfun = partial(self.handle, gsock) acceptor = eventlet.spawn(_eventlet_serve, gsock, hfun, self.worker_connections) acceptors.append(acceptor) eventlet.sleep(0.0) while self.alive: self.notify() eventlet.sleep(1.0) self.notify() try: with eventlet.Timeout(self.cfg.graceful_timeout) as t: [a.kill(eventlet.StopServe()) for a in acceptors] [a.wait() for a in acceptors] except eventlet.Timeout as te: if te != t: raise [a.kill() for a in acceptors]
Example #4
Source File: test_concurrency.py From coveragepy-bbmirror with Apache License 2.0 | 6 votes |
def test_bug_330(self): BUG_330 = """\ from weakref import WeakKeyDictionary import eventlet def do(): eventlet.sleep(.01) gts = WeakKeyDictionary() for _ in range(100): gts[eventlet.spawn(do)] = True eventlet.sleep(.005) eventlet.sleep(.1) print(len(gts)) """ self.try_some_code(BUG_330, "eventlet", eventlet, "0\n")
Example #5
Source File: as13000_nas.py From manila with Apache License 2.0 | 6 votes |
def send_rest_api(self, method, params=None, request_type='post'): attempts = 3 msge = '' while attempts > 0: attempts -= 1 try: return self.send_api(method, params, request_type) except exception.NetworkException as e: msge = six.text_type(e) LOG.error(msge) self.refresh_token(force=True) eventlet.sleep(1) except exception.ShareBackendException as e: msge = six.text_type(e) break msg = (_('Access RestAPI /rest/%(method)s by %(type)s failed,' ' error: %(msge)s') % {'method': method, 'msge': msge, 'type': request_type}) LOG.error(msg) raise exception.ShareBackendException(msg)
Example #6
Source File: ipsec.py From neutron-vpnaas with Apache License 2.0 | 6 votes |
def restart(self): """Restart the process.""" if cfg.CONF.pluto.restart_check_config and not self._config_changed(): return # stop() followed immediately by a start() runs the risk that the # current pluto daemon has not had a chance to shutdown. We check # the current process information to see if the daemon is still # running and if so, wait a short interval and retry. self.stop() wait_interval = cfg.CONF.pluto.shutdown_check_timeout for i in range(cfg.CONF.pluto.shutdown_check_retries): if not self._process_running(): self._cleanup_control_files() break eventlet.sleep(wait_interval) wait_interval *= cfg.CONF.pluto.shutdown_check_back_off else: LOG.warning('Server appears to still be running, restart ' 'of router %s may fail', self.id) self.start() return
Example #7
Source File: geventlet.py From Flask-P2P with MIT License | 6 votes |
def run(self): acceptors = [] for sock in self.sockets: gsock = GreenSocket(sock) gsock.setblocking(1) hfun = partial(self.handle, gsock) acceptor = eventlet.spawn(_eventlet_serve, gsock, hfun, self.worker_connections) acceptors.append(acceptor) eventlet.sleep(0.0) while self.alive: self.notify() eventlet.sleep(1.0) self.notify() try: with eventlet.Timeout(self.cfg.graceful_timeout) as t: [a.kill(eventlet.StopServe()) for a in acceptors] [a.wait() for a in acceptors] except eventlet.Timeout as te: if te != t: raise [a.kill() for a in acceptors]
Example #8
Source File: test_concurrency.py From coveragepy with Apache License 2.0 | 6 votes |
def test_bug_330(self): BUG_330 = """\ from weakref import WeakKeyDictionary import eventlet def do(): eventlet.sleep(.01) gts = WeakKeyDictionary() for _ in range(100): gts[eventlet.spawn(do)] = True eventlet.sleep(.005) eventlet.sleep(.1) print(len(gts)) """ self.try_some_code(BUG_330, "eventlet", eventlet, "0\n")
Example #9
Source File: test_periodics.py From futurist with Apache License 2.0 | 6 votes |
def test_add_on_demand(self): called = set() def cb(name): called.add(name) callables = [] for i in range(0, 10): i_cb = functools.partial(cb, '%s_has_called' % i) callables.append((every_half_sec, (i_cb,), {})) leftover_callables = list(callables) w = periodics.PeriodicWorker([], **self.worker_kwargs) with self.create_destroy(w.start, allow_empty=True): # NOTE(harlowja): if this never happens, the test will fail # eventually, with a timeout error..., probably can make it fail # slightly faster in the future... while len(called) != len(callables): if leftover_callables: cb, args, kwargs = leftover_callables.pop() w.add(cb, *args, **kwargs) self.sleep(0.1) w.stop()
Example #10
Source File: test_periodics.py From futurist with Apache License 2.0 | 6 votes |
def test_worker(self): called = [] def cb(): called.append(1) callables = [ (every_one_sec, (cb,), None), (every_half_sec, (cb,), None), ] executor = self.executor_cls(**self.executor_kwargs) executor_factory = lambda: executor w = periodics.PeriodicWorker(callables, executor_factory=executor_factory, **self.worker_kwargs) with self.create_destroy(w.start): self.sleep(2.0) w.stop() am_called = sum(called) self.assertGreaterEqual(am_called, 4) self.assertFalse(executor.alive)
Example #11
Source File: test_periodics.py From futurist with Apache License 2.0 | 6 votes |
def test_create_with_arguments(self): m = mock.Mock() class Object(object): @periodics.periodic(0.5) def func1(self, *args, **kwargs): m(*args, **kwargs) executor_factory = lambda: self.executor_cls(**self.executor_kwargs) w = periodics.PeriodicWorker.create(objects=[Object()], executor_factory=executor_factory, args=('foo',), kwargs={'bar': 'baz'}, **self.worker_kwargs) with self.create_destroy(w.start): self.sleep(2.0) w.stop() m.assert_called_with('foo', bar='baz')
Example #12
Source File: test_periodics.py From futurist with Apache License 2.0 | 6 votes |
def test_add_with_auto_stop_when_empty_set(self): m = mock.Mock() @periodics.periodic(0.5) def run_only_once(): raise periodics.NeverAgain("No need to run again !!") callables = [ (run_only_once, None, None), ] executor_factory = lambda: self.executor_cls(**self.executor_kwargs) w = periodics.PeriodicWorker(callables, executor_factory=executor_factory, **self.worker_kwargs) with self.create_destroy(w.start, auto_stop_when_empty=True): self.sleep(2.0) w.add(every_half_sec, m, None) m.assert_not_called()
Example #13
Source File: test_periodics.py From futurist with Apache License 2.0 | 6 votes |
def test_retry_submission(self): called = [] def cb(): called.append(1) callables = [ (every_one_sec, (cb,), None), (every_half_sec, (cb,), None), ] w = periodics.PeriodicWorker(callables, executor_factory=RejectingExecutor, cond_cls=green_threading.Condition, event_cls=green_threading.Event) w._RESCHEDULE_DELAY = 0 w._RESCHEDULE_JITTER = 0 with create_destroy_green_thread(w.start): eventlet.sleep(2.0) w.stop() am_called = sum(called) self.assertGreaterEqual(am_called, 4)
Example #14
Source File: test_wsgi.py From masakari with Apache License 2.0 | 6 votes |
def test_uri_length_limit(self): server = masakari.wsgi.Server("test_uri_length_limit", None, host="127.0.0.1", max_url_len=16384) server.start() uri = "http://127.0.0.1:%d/%s" % (server.port, 10000 * 'x') resp = requests.get(uri, proxies={"http": ""}) eventlet.sleep(0) self.assertNotEqual(resp.status_code, requests.codes.REQUEST_URI_TOO_LARGE) uri = "http://127.0.0.1:%d/%s" % (server.port, 20000 * 'x') resp = requests.get(uri, proxies={"http": ""}) eventlet.sleep(0) self.assertEqual(resp.status_code, requests.codes.REQUEST_URI_TOO_LARGE) server.stop() server.wait()
Example #15
Source File: zmq_pubsub_driver.py From dragonflow with Apache License 2.0 | 6 votes |
def run(self): self.connect() LOG.info("Starting Subscriber on ports %(endpoints)s", {'endpoints': self.uri_list}) while True: try: eventlet.sleep(0) [topic, data] = self.sub_socket.recv_multipart() self._handle_incoming_event(data) except Exception: exception_tb = traceback.format_exc() LOG.warning('Exception caught.\n%s', (exception_tb,)) self.sub_socket.close() self.connect() self.db_changes_callback(None, None, 'sync', None, None)
Example #16
Source File: base.py From st2 with Apache License 2.0 | 6 votes |
def make_mock_stream_readline(mock_stream, mock_data, stop_counter=1, sleep_delay=0): mock_stream.counter = 0 def mock_stream_readline(): if sleep_delay: eventlet.sleep(sleep_delay) if mock_stream.counter >= stop_counter: mock_stream.closed = True return line = mock_data[mock_stream.counter] mock_stream.counter += 1 return line return mock_stream_readline
Example #17
Source File: test_periodics.py From futurist with Apache License 2.0 | 6 votes |
def test_start_with_auto_stop_when_empty_set(self): @periodics.periodic(0.5) def run_only_once(): raise periodics.NeverAgain("No need to run again !!") callables = [ (run_only_once, None, None), (run_only_once, None, None), ] executor_factory = lambda: self.executor_cls(**self.executor_kwargs) w = periodics.PeriodicWorker(callables, executor_factory=executor_factory, **self.worker_kwargs) with self.create_destroy(w.start, auto_stop_when_empty=True): self.sleep(2.0) for watcher in w.iter_watchers(): self.assertGreaterEqual(watcher.runs, 1) self.assertGreaterEqual(watcher.successes, 1) self.assertEqual(watcher.failures, 0) self.assertEqual(watcher.requested_stop, True)
Example #18
Source File: test_wsgi.py From oslo.service with Apache License 2.0 | 6 votes |
def test_uri_length_limit(self): eventlet.monkey_patch(os=False, thread=False) server = wsgi.Server(self.conf, "test_uri_length_limit", None, host="127.0.0.1", max_url_len=16384, port=33337) server.start() self.assertFalse(server._server.dead) uri = "http://127.0.0.1:%d/%s" % (server.port, 10000 * 'x') resp = requests.get(uri, proxies={"http": ""}) eventlet.sleep(0) self.assertNotEqual(requests.codes.REQUEST_URI_TOO_LARGE, resp.status_code) uri = "http://127.0.0.1:%d/%s" % (server.port, 20000 * 'x') resp = requests.get(uri, proxies={"http": ""}) eventlet.sleep(0) self.assertEqual(requests.codes.REQUEST_URI_TOO_LARGE, resp.status_code) server.stop() server.wait()
Example #19
Source File: plugin.py From tacker with Apache License 2.0 | 6 votes |
def config_vnf(self, context, vnf_dict): config = vnf_dict['attributes'].get('config') if not config: return if isinstance(config, str): # TODO(dkushwaha) remove this load once db supports storing # json format of yaml files in a separate column instead of # key value string pairs in vnf attributes table. config = yaml.safe_load(config) eventlet.sleep(self.boot_wait) # wait for vm to be ready vnf_id = vnf_dict['id'] update = { 'vnf': { 'id': vnf_id, 'attributes': {'config': config}, } } self.update_vnf(context, vnf_id, update)
Example #20
Source File: utils.py From tacker with Apache License 2.0 | 6 votes |
def cooperative_iter(iter): """Prevent eventlet thread starvation during iteration Return an iterator which schedules after each iteration. This can prevent eventlet thread starvation. :param iter: an iterator to wrap """ try: for chunk in iter: sleep(0) yield chunk except Exception as err: with excutils.save_and_reraise_exception(): msg = _("Error: cooperative_iter exception %s") % err LOG.error(msg)
Example #21
Source File: test_scheduling.py From watcher with Apache License 2.0 | 6 votes |
def test_execute_sync_job_fails(self, m_start, m_list_available, m_load, m_list, m_save): fake_config = mock.Mock(period=.01) fake_collector = faker_cluster_state.FakerModelCollector( config=fake_config) fake_collector.synchronize = mock.Mock( side_effect=lambda: eventlet.sleep(.5)) m_list_available.return_value = { 'fake': faker_cluster_state.FakerModelCollector} m_load.return_value = fake_collector scheduler = scheduling.DecisionEngineSchedulingService() scheduler.start() m_start.assert_called_once_with(scheduler) jobs = scheduler.get_jobs() self.assertEqual(2, len(jobs)) job = jobs[0] job.func() self.assertFalse(bool(fake_collector.cluster_data_model)) self.assertIsInstance(job.trigger, interval_trigger.IntervalTrigger)
Example #22
Source File: file_watch_sensor.py From st2 with Apache License 2.0 | 6 votes |
def add_trigger(self, trigger): file_path = trigger['parameters'].get('file_path', None) if not file_path: self._logger.error('Received trigger type without "file_path" field.') return self._trigger = trigger.get('ref', None) if not self._trigger: raise Exception('Trigger %s did not contain a ref.' % trigger) # Wait a bit to avoid initialization race in logshipper library eventlet.sleep(1.0) self._tail.add_file(filename=file_path) self._logger.info('Added file "%s"' % (file_path))
Example #23
Source File: python-mock-create-vm.py From st2 with Apache License 2.0 | 5 votes |
def run(self, cpu_cores, memory_mb, vm_name, ip): eventlet.sleep(5) data = { 'vm_id': 'vm' + str(random.randint(0, 10000)), ip: { 'cpu_cores': cpu_cores, 'memory_mb': memory_mb, 'vm_name': vm_name } } return data
Example #24
Source File: base.py From st2 with Apache License 2.0 | 5 votes |
def _wait_on_status(self, liveaction_db, status, retries=300, delay=0.1, raise_exc=True): assert isinstance(status, six.string_types), '%s is not of text type' % (status) for _ in range(0, retries): eventlet.sleep(delay) liveaction_db = LiveAction.get_by_id(str(liveaction_db.id)) if liveaction_db.status == status: break if raise_exc: self.assertEqual(liveaction_db.status, status) return liveaction_db
Example #25
Source File: test_performance.py From st2 with Apache License 2.0 | 5 votes |
def test_concurrent_load(self): load_count = 3 delay_poll = load_count * 5 wf_name = 'examples.orquesta-mock-create-vm' wf_input = {'vm_name': 'demo1', 'meta': {'demo1.itests.org': '10.3.41.99'}} exs = [self._execute_workflow(wf_name, wf_input) for i in range(load_count)] eventlet.sleep(delay_poll) for ex in exs: e = self._wait_for_completion(ex) self.assertEqual(e.status, ac_const.LIVEACTION_STATUS_SUCCEEDED, json.dumps(e.result)) self.assertIn('output', e.result) self.assertIn('vm_id', e.result['output'])
Example #26
Source File: base.py From st2 with Apache License 2.0 | 5 votes |
def _wait_on_ac_ex_status(self, execution_db, status, retries=300, delay=0.1, raise_exc=True): for _ in range(0, retries): eventlet.sleep(delay) execution_db = ex_db_access.ActionExecution.get_by_id(str(execution_db.id)) if execution_db.status == status: break if raise_exc: self.assertEqual(execution_db.status, status) return execution_db
Example #27
Source File: base.py From st2 with Apache License 2.0 | 5 votes |
def _wait_on_call_count(self, mocked, expected_count, retries=100, delay=0.1, raise_exc=True): for _ in range(0, retries): eventlet.sleep(delay) if mocked.call_count == expected_count: break if raise_exc: self.assertEqual(mocked.call_count, expected_count)
Example #28
Source File: test_resultstracker.py From st2 with Apache License 2.0 | 5 votes |
def test_query_process(self): tracker = self._get_tracker() runners_utils.invoke_post_run = mock.Mock(return_value=None) # Ensure state objects are present. state1 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state1.yaml'].id) state2 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state2.yaml'].id) self.assertIsNotNone(state1) self.assertIsNotNone(state2) # Process the state objects. tracker._bootstrap() eventlet.sleep(1) exec_id = str(ResultsTrackerTests.states['state1.yaml'].execution_id) exec_db = LiveAction.get_by_id(exec_id) self.assertIsNotNone(exec_db.result['called_with'][exec_id], exec_db.result) exec_id = str(ResultsTrackerTests.states['state2.yaml'].execution_id) exec_db = LiveAction.get_by_id(exec_id) self.assertIsNotNone(exec_db.result['called_with'][exec_id], exec_db.result) tracker.shutdown() # Ensure state objects are deleted. self.assertRaises( StackStormDBObjectNotFoundError, ActionExecutionState.get_by_id, ResultsTrackerTests.states['state1.yaml'].id ) self.assertRaises( StackStormDBObjectNotFoundError, ActionExecutionState.get_by_id, ResultsTrackerTests.states['state2.yaml'].id ) # Ensure invoke_post_run is called. self.assertEqual(2, runners_utils.invoke_post_run.call_count)
Example #29
Source File: test_resultstracker.py From st2 with Apache License 2.0 | 5 votes |
def test_start_shutdown(self): tracker = self._get_tracker() tracker.start() eventlet.sleep(0.1) tracker.shutdown()
Example #30
Source File: st2-inject-trigger-instances.py From st2 with Apache License 2.0 | 5 votes |
def _inject_instances(trigger, rate_per_trigger, duration, payload=None, max_throughput=False): payload = payload or {} start = date_utils.get_datetime_utc_now() elapsed = 0.0 count = 0 dispatcher = TriggerDispatcher() while elapsed < duration: # print('Dispatching trigger %s at time %s', trigger, date_utils.get_datetime_utc_now()) dispatcher.dispatch(trigger, payload) if rate_per_trigger: # NOTE: We decrease sleep delay for 56% to take into account overhead / delay because # of the call to dispatchet.dispatch method. delta = random.expovariate(rate_per_trigger) eventlet.sleep(delta * 0.56) elapsed = (date_utils.get_datetime_utc_now() - start).seconds count += 1 actual_rate = int(count / elapsed) print('%s: Emitted %d triggers in %d seconds (actual rate=%s triggers / second)' % (trigger, count, elapsed, actual_rate)) # NOTE: Due to the overhead of dispatcher.dispatch call, we allow for 10% of deviation from # requested rate before warning if rate_per_trigger and (actual_rate < (rate_per_trigger * 0.9)): print('') print('Warning, requested rate was %s triggers / second, but only achieved %s ' 'triggers / second' % (rate_per_trigger, actual_rate)) print('Too increase the throuput you will likely need to run multiple instances of ' 'this script in parallel.')