def close(self): """Closes the described file. Attention! Unlike Python semantics, `close' does not return `None' upon success but `0', to be able to return an exit code for popen'ed files. The actual return value may be determined with os.WEXITSTATUS. """ res = 0 ll_file = self._ll_file if ll_file: # double close is allowed self._ll_file = lltype.nullptr(FILEP.TO) rgc.may_ignore_finalizer(self) do_close = self._close2[0] try: if do_close: res = do_close(ll_file) if res == -1: errno = rposix.get_saved_errno() raise IOError(errno, os.strerror(errno)) finally: if self._setbuf: lltype.free(self._setbuf, flavor='raw') self._setbuf = lltype.nullptr(rffi.CCHARP.TO) return res
def _invoke_execute_frame(self, w_arg_or_err): space = self.space frame = self.frame if self.running: raise oefmt(space.w_ValueError, "%s already executing", self.KIND) # # Optimization only: after we've started a Coroutine without # CO_YIELD_INSIDE_TRY, then Coroutine._finalize_() will be a no-op if frame.last_instr == -1: if (isinstance(self, Coroutine) and not (self.pycode.co_flags & CO_YIELD_INSIDE_TRY)): rgc.may_ignore_finalizer(self) if (not space.is_w(w_arg_or_err, space.w_None) and not isinstance(w_arg_or_err, SApplicationException)): raise oefmt(space.w_TypeError, "can't send non-None value to a just-started %s", self.KIND) ec = space.getexecutioncontext() current_exc_info = ec.sys_exc_info() if self.saved_operr is not None: ec.set_sys_exc_info(self.saved_operr) self.saved_operr = None self.running = True try: w_result = frame.execute_frame(w_arg_or_err) except OperationError as e: # errors finish a frame try: if e.match(space, space.w_StopIteration): self._leak_stopiteration(e) elif (isinstance(self, AsyncGenerator) and e.match(space, space.w_StopAsyncIteration)): self._leak_stopasynciteration(e) finally: self.frame_is_finished() raise finally: frame.f_backref = jit.vref_None self.running = False # note: this is not perfectly correct: see # test_exc_info_in_generator_4. But it's simpler and # bug-to-bug compatible with CPython 3.5 and 3.6. if frame._any_except_or_finally_handler(): self.saved_operr = ec.sys_exc_info() ec.set_sys_exc_info(current_exc_info) return w_result
def fn(): for i in range(1000): x = A(i) fq.register_finalizer(x) rgc.may_ignore_finalizer(x) # this is ignored with Boehm rgc.collect() rgc.collect() if glob.triggered == 0: print "not triggered!" return 50 seen = {} while True: a = fq.next_dead() if a is None: break assert a.i not in seen seen[a.i] = True if len(seen) < 500: print "seen only %d!" % len(seen) return 51 return 42
def frame_is_finished(self): self.frame = None rgc.may_ignore_finalizer(self)
def _do_exit(self): if not self.explicitly_freed: rgc.add_memory_pressure(-self._sizeof(), self) self.explicitly_freed = True rgc.may_ignore_finalizer(self) lltype.free(self._ptr, flavor='raw')
def _do_exit(self): if self.datasize >= 0: rgc.add_memory_pressure(-self.datasize, self) self.datasize = -1 rgc.may_ignore_finalizer(self) lltype.free(self._ptr, flavor='raw')