def test_periodic_action(self): from pypy.interpreter.executioncontext import ActionFlag class DemoAction(executioncontext.PeriodicAsyncAction): counter = 0 def perform(self, ec, frame): self.counter += 1 print '->', self.counter if self.counter == 3: raise Finished space = self.space a2 = DemoAction(space) try: space.actionflag.setcheckinterval(100) space.actionflag.register_periodic_action(a2, True) try: for i in range(500): space.appexec([], """(): n = 5 return n + 2 """) except Finished: pass finally: space.actionflag = ActionFlag() # reset to default assert 10 < i < 110
def __init__(self, config=None): "NOT_RPYTHON: Basic initialization of objects." self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit # sets all the internal descriptors if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config # import extra modules for side-effects import pypy.interpreter.nestedscope # register *_DEREF bytecodes self.interned_strings = {} self.actionflag = ActionFlag() # changed by the signal module self.user_del_action = UserDelAction(self) self.frame_trace_action = FrameTraceAction(self) self.actionflag.register_action(self.user_del_action) self.actionflag.register_action(self.frame_trace_action) from pypy.interpreter.pyframe import PyFrame self.FrameClass = PyFrame # can be overridden to a subclass # if self.config.objspace.logbytecodes: # self.bytecodecounts = {} self.initialize()
def __init__(self, config=None): """NOT_RPYTHON""" self.fromcache = InternalSpaceCache(self).getorbuild self.w_Ellipsis = special.Ellipsis() self.w_NotImplemented = special.NotImplemented() if config is None: from pypy.config.pypyoption import get_pypy_config config = get_pypy_config(translating=False) self.config = config self.interned_strings = make_weak_value_dictionary(self, str, W_Root) self.builtin = DictObject({}) self.FrameClass = PyFrame self.threadlocals = ThreadLocals() self.actionflag = ActionFlag() # changed by the signal module self.check_signal_action = None # changed by the signal module