Python eventlet.spawn_after() Examples
The following are 9
code examples of eventlet.spawn_after().
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: hub.py From ryu with Apache License 2.0 | 6 votes |
def spawn_after(seconds, *args, **kwargs): def _launch(func, *args, **kwargs): # mimic gevent's default raise_error=False behaviour # by not propergating an exception to the joiner. try: func(*args, **kwargs) except greenlet.GreenletExit: pass except: # log uncaught exception. # note: this is an intentional divergence from gevent # behaviour. gevent silently ignores such exceptions. LOG.error('hub: uncaught exception: %s', traceback.format_exc()) return eventlet.spawn_after(seconds, _launch, *args, **kwargs)
Example #2
Source File: hybrid_driver.py From sdc-live-trainer with MIT License | 6 votes |
def init_gui(self): # Create the root window self.root = tkinter.Tk() self.root.geometry('350x75+490+550') self.root.title('Hybrid driver') # Create a label with status self.status = tkinter.StringVar() label = tkinter.Label(self.root, width=350, height=75, textvariable=self.status) label.pack(fill=tkinter.BOTH, expand=1) # Bind key event handlers self.root.bind('<Left>', lambda e: self.turn_left()) self.root.bind('<Right>', lambda e: self.turn_right()) self.root.bind('<Up>', lambda e: self.speed_up()) self.root.bind('<Down>', lambda e: self.slow_down()) self.root.bind('<Key>', self.keydown) self.update_status() # Start UI loop eventlet.spawn_after(1, self.main_loop)
Example #3
Source File: manual_driver.py From sdc-live-trainer with MIT License | 6 votes |
def init_gui(self): # Create the root window self.root = tkinter.Tk() self.root.geometry('350x75+490+550') self.root.title('Manual driver') # Create a label with status self.status = tkinter.StringVar() label = tkinter.Label(self.root, width=350, height=75, textvariable=self.status) label.pack(fill=tkinter.BOTH, expand=1) # Bind key event handlers self.root.bind('<Left>', lambda e: self.turn_left()) self.root.bind('<Right>', lambda e: self.turn_right()) self.root.bind('<Up>', lambda e: self.speed_up()) self.root.bind('<Down>', lambda e: self.slow_down()) self.root.bind('<Key>', self.keydown) self.update_status() # Start UI loop eventlet.spawn_after(1, self.main_loop)
Example #4
Source File: live_trainer.py From sdc-live-trainer with MIT License | 6 votes |
def init_gui(self): # Create the root window self.root = tkinter.Tk() self.root.geometry('350x75+490+550') self.root.title('SDC Live Trainer') # Create a label with status self.status = tkinter.StringVar() label = tkinter.Label(self.root, width=350, height=75, textvariable=self.status) label.pack(fill=tkinter.BOTH, expand=1) # Bind key event handlers self.root.bind('<Left>', lambda e: self.turn_left()) self.root.bind('<Right>', lambda e: self.turn_right()) self.root.bind('<Up>', lambda e: self.speed_up()) self.root.bind('<Down>', lambda e: self.slow_down()) self.root.bind('<Key>', self.keydown) self.update_status() # Start UI loop eventlet.spawn_after(1, self.main_loop)
Example #5
Source File: manager.py From dino with Apache License 2.0 | 5 votes |
def __init__(self, env: GNEnvironment): self._lock = Semaphore(value=1) self.env = env self.to_check = dict() self.heartbeat_sids = set() self.expire_second = env.config.get(ConfigKeys.TIMEOUT, domain=ConfigKeys.HEARTBEAT, default=300) self.sleep_time = env.config.get(ConfigKeys.INTERVAL, domain=ConfigKeys.HEARTBEAT, default=20) eventlet.spawn_after(func=self.loop, seconds=10)
Example #6
Source File: decorators.py From dino with Apache License 2.0 | 5 votes |
def respond_with(gn_event_name=None, should_disconnect=False, emit_response=True): def factory(view_func): @wraps(view_func) def decorator(*args, **kwargs): tb = None try: status_code, data = view_func(*args, **kwargs) except Exception as e: environ.env.stats.incr(gn_event_name + '.exception') tb = traceback.format_exc() logger.error('%s: %s' % (gn_event_name, str(e))) environ.env.capture_exception(sys.exc_info()) if should_disconnect and environ.env.config.get(ConfigKeys.DISCONNECT_ON_FAILED_LOGIN, False): eventlet.spawn_after(seconds=1, func=_delayed_disconnect, sid=environ.env.request.sid) return 500, str(e) finally: if tb is not None: logger.exception(tb) if status_code != 200: logger.warning('in decorator, status_code: %s, data: %s' % (status_code, str(data))) if should_disconnect and environ.env.config.get(ConfigKeys.DISCONNECT_ON_FAILED_LOGIN, False): eventlet.spawn_after(seconds=1, func=_delayed_disconnect, sid=environ.env.request.sid) # in some cases the callback is enough if emit_response: response_message = environ.env.response_formatter(status_code, data) environ.env.emit(gn_event_name, response_message) return status_code, None return decorator return factory
Example #7
Source File: aging.py From dragonflow with Apache License 2.0 | 5 votes |
def switch_sync_finished(self): if self.do_aging: # Give apps a few more seconds to finish their magic eventlet.spawn_after(5, self._start_aging) LOG.info("Scheduled aged flows deletion")
Example #8
Source File: time_trigger.py From karbor with Apache License 2.0 | 5 votes |
def _start(self, first_run_time): self._running = True now = datetime.utcnow() initial_delay = 0 if first_run_time <= now else ( int(timeutils.delta_seconds(now, first_run_time))) self._thread = eventlet.spawn_after( initial_delay, self._run, first_run_time) self._thread.link(self._on_done)
Example #9
Source File: environ.py From dino with Apache License 2.0 | 4 votes |
def delete_ephemeral_rooms(gn_env: GNEnvironment): from activitystreams import parse as as_parser if len(gn_env.config) == 0 or gn_env.config.get(ConfigKeys.TESTING, False): # assume we're testing return def delete(): from dino import utils channel_dict = gn_env.db.get_channels() for channel_id, *_ in channel_dict.items(): rooms = gn_env.db.rooms_for_channel(channel_id) for room_id, room_info in rooms.items(): short_id = room_id.split('-')[0] room_name = room_info['name'] logger.debug('checking room %s: %s' % (room_id, room_name)) users = gn_env.db.users_in_room(room_id) if len(users) > 0: logger.debug('[%s] NOT removing room (%s), has % user(s) in it' % (short_id, room_name, len(users))) continue if not room_info['ephemeral']: logger.debug('[%s] NOT removing room (%s), not ephemeral' % (short_id, room_name)) continue logger.info('[%s] removing ephemeral room (%s)' % (short_id, room_name)) try: gn_env.db.get_room_name(room_id) except NoSuchRoomException: logger.info('[%s] ephemeral room (%s) has already been removed' % (short_id, room_name)) continue activity = utils.activity_for_remove_room('0', 'server', room_id, room_name, 'empty ephemeral room') gn_env.db.remove_room(channel_id, room_id) # no need to notify for wio if gn_env.node is not None and 'wio' not in gn_env.node: gn_env.out_of_scope_emit( 'gn_room_removed', activity, broadcast=True, include_self=True, namespace='/ws') gn_env.observer.emit('on_remove_room', (activity, as_parser(activity))) eventlet.spawn_after(seconds=30*60, func=delete)