def run(self): """Run the target function periodically.""" # Do not use the threading._active_limbo_lock here because it's a gevent lock threading._active[self._tident] = self self._periodic_started = True try: while self.quit is False: self._target() slept = 0 while self.quit is False and slept < self.interval: nogevent.sleep(self.SLEEP_INTERVAL) slept += self.SLEEP_INTERVAL if self._on_shutdown is not None: self._on_shutdown() except Exception: # Exceptions might happen during interpreter shutdown. # We're mimicking what `threading.Thread` does in daemon mode, we ignore them. # See `threading.Thread._bootstrap` for details. if sys is not None: raise finally: try: self._periodic_stopped = True del threading._active[self._tident] except Exception: # Exceptions might happen during interpreter shutdown. # We're mimicking what `threading.Thread` does in daemon mode, we ignore them. # See `threading.Thread._bootstrap` for details. if sys is not None: raise
def test_exception_collection(): r = recorder.Recorder() c = stack.StackCollector(r) with c: try: raise ValueError("hello") except Exception: nogevent.sleep(1) exception_events = r.events[stack.StackExceptionSampleEvent] assert len(exception_events) >= 1 e = exception_events[0] assert e.timestamp > 0 assert e.sampling_period > 0 assert e.thread_id == nogevent.thread_get_ident() assert e.thread_name == "MainThread" assert e.frames == [(__file__, 321, "test_exception_collection")] assert e.nframes == 1 assert e.exc_type == ValueError
def test_exception_collection_trace(tracer): r = recorder.Recorder() c = stack.StackCollector(r, tracer=tracer) with c: with tracer.trace("test123") as span: try: raise ValueError("hello") except Exception: nogevent.sleep(1) exception_events = r.events[stack.StackExceptionSampleEvent] assert len(exception_events) >= 1 e = exception_events[0] assert e.timestamp > 0 assert e.sampling_period > 0 assert e.thread_id == nogevent.thread_get_ident() assert e.thread_name == "MainThread" assert e.frames == [(__file__, 344, "test_exception_collection_trace")] assert e.nframes == 1 assert e.exc_type == ValueError assert e.span_id == span.span_id assert e.trace_id == span.trace_id
def func5(): return nogevent.sleep(1)