Author: Antonio Cuni <anto.c...@gmail.com> Branch: continulet-no-frame-loop Changeset: r93029:ba1ff85734b9 Date: 2017-11-15 01:43 +0100 http://bitbucket.org/pypy/pypy/changeset/ba1ff85734b9/
Log: WIP: add two temporary flags which allow to select: 1) the old switch logic vs the new one and 2) whether to print or not debug infos diff --git a/pypy/module/_continuation/interp_continuation.py b/pypy/module/_continuation/interp_continuation.py --- a/pypy/module/_continuation/interp_continuation.py +++ b/pypy/module/_continuation/interp_continuation.py @@ -41,7 +41,7 @@ bottomframe.locals_cells_stack_w[3] = w_kwds bottomframe.last_exception = get_cleared_operation_error(space) self.bottomframe = bottomframe - self.topframe = sthread.ec.topframeref # XXX? + self.topframeref = sthread.ec.topframeref # global_state.origin = self self.sthread = sthread @@ -79,11 +79,9 @@ global_state.origin = self if to is None: # simple switch: going to self.h - #print 'simple switch' global_state.destination = self else: # double switch: the final destination is to.h - #print 'double switch' global_state.destination = to # h = sthread.switch(global_state.destination.h) @@ -221,24 +219,6 @@ global_state = GlobalState() global_state.clear() - -def pstack(cont, message=''): - return - if message: - print message - if isinstance(cont, jit.DirectJitVRef): - f = cont() - else: - f = cont.bottomframe - i = 0 - while f: - print ' ', f.pycode.co_name - f = f.f_backref() - i += 1 - if i == 10: - break - print - def new_stacklet_callback(h, arg): self = global_state.origin self.h = h @@ -256,35 +236,66 @@ global_state.destination = self return self.h +DEBUG = False +ORIGINAL = False + +def log(x=''): + if DEBUG: + print x + +def pstack(cont, message=''): + """ + NOTE: I don't know exactly why, but sometimes if you pstack() a sthread or + a frame, then later you get an InvalidVirtualRef exception. So, in + general, this is a useful debugging tool but don't expect your tests to + pass if you call it. Put DEBUG=False to disable. + """ + if not DEBUG: + return + if message: + print message + if isinstance(cont, jit.DirectJitVRef): + f = cont() + else: + f = cont.bottomframe + i = 0 + while f: + print ' ', f.pycode.co_name + f = f.f_backref() + i += 1 + if i == 10: + break + print + def post_switch(sthread, h): origin = global_state.origin self = global_state.destination - #import pdb;pdb.set_trace() global_state.origin = None global_state.destination = None self.h, origin.h = origin.h, h # current = sthread.ec.topframeref - print '==== SWITCH ====' + lo + g('==== SWITCH ====') pstack(sthread.ec.topframeref, 'sthread.ec.topframeref') pstack(self, 'self') - # ORGINAL - ## sthread.ec.topframeref = self.bottomframe.f_backref - ## self.bottomframe.f_backref = origin.bottomframe.f_backref - ## origin.bottomframe.f_backref = current - - # antocuni - sthread.ec.topframeref = self.topframe - self.topframe = origin.topframe - origin.topframe = current - + if ORIGINAL: + sthread.ec.topframeref = self.bottomframe.f_backref + self.bottomframe.f_backref = origin.bottomframe.f_backref + origin.bottomframe.f_backref = current + else: + # antocuni + sthread.ec.topframeref = self.topframeref + self.topframeref = origin.topframeref + origin.topframeref = current # - print 'swap' + log('swap') pstack(sthread.ec.topframeref, 'sthread.ec.topframeref') - pstack(self, 'self') - print '==== END SWITCH ====' - print + pstack(self + , 'self') + log('==== END SWITCH ====') + log() return get_result() def get_result(): @@ -315,7 +326,8 @@ if cont.sthread is None: continue # ignore non-initialized continulets else: - raise geterror(space, "inter-thread support is missing") + raise geterror(space + , "inter-thread support is missing") elif sthread.is_empty_handle(cont.h): raise geterror(space, "got an already-finished continulet") contlist.append(cont) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit