def initialize_as_generator(self, name, qualname): space = self.space if self.getcode().co_flags & pycode.CO_COROUTINE: from pypy.interpreter.generator import Coroutine gen = Coroutine(self, name, qualname) ec = space.getexecutioncontext() w_wrapper = ec.w_coroutine_wrapper_fn else: from pypy.interpreter.generator import GeneratorIterator gen = GeneratorIterator(self, name, qualname) ec = None w_wrapper = None if space.config.translation.rweakref: self.f_generator_wref = rweakref.ref(gen) else: self.f_generator_nowref = gen w_gen = gen if w_wrapper is not None: if ec.in_coroutine_wrapper: raise oefmt(space.w_RuntimeError, "coroutine wrapper %R attempted " "to recursively wrap %R", w_wrapper, self.getcode()) ec.in_coroutine_wrapper = True try: w_gen = space.call_function(w_wrapper, w_gen) finally: ec.in_coroutine_wrapper = False return w_gen
def _new_pointer_type(space, w_ctype): _setup_wref(rweakref.has_weakref_support()) ctptr = w_ctype._pointer_type() if ctptr is None: ctptr = ctypeptr.W_CTypePointer(space, w_ctype) w_ctype._pointer_type = rweakref.ref(ctptr) return ctptr
def _finalize_(self): if self.frame is not None and self.frame.lastblock is not None: if self.w_finalizer is not None: # XXX: this is a hack to resurrect the weakref that was cleared # before running _finalize_() if self.space.config.translation.rweakref: self.frame.f_generator_wref = rweakref.ref(self) try: self.space.call_function(self.w_finalizer, self) except OperationError as e: e.write_unraisable(self.space, "async generator finalizer") return GeneratorOrCoroutine._finalize_(self)
def __init__(self, key, value): assert isinstance(key, W_Object) assert isinstance(value, W_Object) self.key = weakref.ref(key) self.mapping = weakref.RWeakKeyDictionary(W_Object, W_Object) self.mapping.set(key, value)
def __init__(self, value): assert isinstance(value, W_Object) self.value = weakref.ref(value)
def __init__(self, w_iobase): self.w_iobase_ref = rweakref.ref(w_iobase) w_iobase.autoflusher = self