def iter_context_objects(self): """Returns an iterator over all objects for the combined application and context cache. """ use_gevent = is_gevent_enabled() use_context = is_context_enabled() if use_gevent: tid = greenlet_get_ident() elif use_context: tid = context_get_ident() else: tid = thread_get_ident() objects = self._cache.get(tid) if objects is None: if len(self._cache) > _MAX_CONTEXT_OBJECT_CACHE: self._cache.clear() objects = self._global[:] objects.extend(getattr(self._thread_context, 'stack', ())) if use_gevent: objects.extend(getattr(self._greenlet_context, 'stack', ())) if use_context: objects.extend(self._context_stack.get([])) objects.sort(reverse=True) objects = [x[1] for x in objects] self._cache[tid] = objects return iter(objects)
def iter_context_objects(self): """Returns an iterator over all objects for the combined application and context cache. """ use_gevent = is_gevent_enabled() tid = greenlet_get_ident() if use_gevent else thread_get_ident() objects = self._cache.get(tid) if objects is None: if len(self._cache) > _MAX_CONTEXT_OBJECT_CACHE: self._cache.clear() objects = self._global[:] objects.extend(getattr(self._thread_context, 'stack', ())) if use_gevent: objects.extend(getattr(self._greenlet_context, 'stack', ())) objects.sort(reverse=True) objects = [x[1] for x in objects] self._cache[tid] = objects return iter(objects)
def deactivate(self): from logbook.concurrency import is_gevent_enabled if is_gevent_enabled(): self.handler.pop_greenlet() else: self.handler.pop_thread()
def __exit__(self, exc_type, exc_value, tb): if is_gevent_enabled(): self.pop_greenlet() else: self.pop_thread()
def __enter__(self): if is_gevent_enabled(): self.push_greenlet() else: self.push_thread() return self