def run(self): self.unblock_test() self.wait_for_test() print('Action completed [eventlet_id=%s]' % corolocal.get_ident()) return 'test'
def run(self, context): self.unblock_test() self.wait_for_test() print('Action completed [eventlet_id=%s]' % corolocal.get_ident()) return 'test'
def set_ctx(new_ctx): ident = corolocal.get_ident() if not new_ctx and ident in _CTXS._curr_ctxs: del _CTXS._curr_ctxs[ident] if new_ctx: _CTXS._curr_ctxs[ident] = new_ctx
def set_ctx(new_ctx): ident = corolocal.get_ident() if not new_ctx and ident in _CURR_CTXS: del _CURR_CTXS[ident] if new_ctx: _CURR_CTXS[ident] = new_ctx
def set_thread_local(var_name, val): if not val and has_thread_local(var_name): gl_storage = _get_greenlet_local_storage() # Delete variable from greenlet local storage. if gl_storage: del gl_storage[var_name] # Delete the entire greenlet local storage from thread local storage. if gl_storage and len(gl_storage) == 0: del _th_loc_storage.greenlet_locals[corolocal.get_ident()] if val: gl_storage = _get_greenlet_local_storage() if not gl_storage: gl_storage = _th_loc_storage.greenlet_locals[corolocal.get_ident()] = {} gl_storage[var_name] = val
def set_thread_local(var_name, val): if val is None and has_thread_local(var_name): gl_storage = _get_greenlet_local_storage() # Delete variable from greenlet local storage. if gl_storage: del gl_storage[var_name] # Delete the entire greenlet local storage from thread local storage. if gl_storage and len(gl_storage) == 0: del _th_loc_storage.greenlet_locals[corolocal.get_ident()] if val is not None: gl_storage = _get_greenlet_local_storage() if not gl_storage: gl_storage = _th_loc_storage.greenlet_locals[ corolocal.get_ident()] = {} gl_storage[var_name] = val
def _get_greenlet_local_storage(): greenlet_id = corolocal.get_ident() greenlet_locals = getattr(_th_loc_storage, "greenlet_locals", None) if not greenlet_locals: greenlet_locals = {} _th_loc_storage.greenlet_locals = greenlet_locals if greenlet_id in greenlet_locals: return greenlet_locals[greenlet_id] else: return None
def _local_close(self, greenlet_id=None): """ called when a greenlet is finished with the context, disposes of local resources. """ # if no greenlet is specified, use the calling greenlet if greenlet_id is None: greenlet_id = get_ident() # remove the local storage references for the greenlet try: del self._locals_by_greenlet[greenlet_id] except KeyError: pass
def __init__(self, path, threaded=True): self.path = path self.lock_file = os.path.abspath(path) + ".lock" self.hostname = socket.gethostname() self.pid = os.getpid() if threaded: t = threading.current_thread() # Thread objects in Python 2.4 and earlier do not have ident # attrs. Worm around that. ident = getattr(t, "ident", hash(t)) or hash(t) gident = corolocal.get_ident() self.tname = "-%x-%x" % (ident & 0xFFFFFFFF, gident & 0xFFFFFFFF) else: self.tname = "" dirname = os.path.dirname(self.lock_file) self.unique_name = os.path.join(dirname, "%s%s.%s" % (self.hostname, self.tname, self.pid))
def __init__(self, path, threaded=True): self.path = path self.lock_file = os.path.abspath(path) + ".lock" self.hostname = socket.gethostname() self.pid = os.getpid() if threaded: t = threading.current_thread() # Thread objects in Python 2.4 and earlier do not have ident # attrs. Worm around that. ident = getattr(t, "ident", hash(t)) or hash(t) gident = corolocal.get_ident() self.tname = "-%x-%x" % (ident & 0xffffffff, gident & 0xffffffff) else: self.tname = "" dirname = os.path.dirname(self.lock_file) self.unique_name = os.path.join( dirname, "%s%s.%s" % (self.hostname, self.tname, self.pid))
def current(cls): try: return cls._contexts[corolocal.get_ident()][-1] except (KeyError, IndexError): raise RuntimeError("Context isn't available here")
def ctx(): if not has_ctx(): # TODO(slukjanov): replace with specific error raise RuntimeError("Context isn't available here") return _CTXS._curr_ctxs[corolocal.get_ident()]
def has_ctx(): ident = corolocal.get_ident() return ident in _CTXS._curr_ctxs and _CTXS._curr_ctxs[ident]
def _get_ident(self): from eventlet.corolocal import get_ident return super(ContextStackManagerEventletMixin, self)._get_ident() + (get_ident(), )
def __exit__(self, exc_type, exc_val, exc_tb): stack = self._contexts[corolocal.get_ident()] stack.pop() if not stack: del self._contexts[corolocal.get_ident()]
def __enter__(self): stack = self._contexts.setdefault(corolocal.get_ident(), []) stack.append(self)
def has_ctx(): ident = corolocal.get_ident() return ident in _CURR_CTXS and _CURR_CTXS[ident]
def _get_ident(self): from eventlet.corolocal import get_ident return super( ContextStackManagerEventletMixin, self )._get_ident() + (get_ident(), )
def filter(self, record): record.greenlet = corolocal.get_ident() return True
def clear(cls): try: del cls._contexts[corolocal.get_ident()] except KeyError: pass
def ctx(): if not has_ctx(): raise RuntimeError("Context isn't available here") return _CURR_CTXS[corolocal.get_ident()]