def findFrame(thread_id, frame_id): """ returns a frame on the thread that has a given frame_id """ try: curr_thread_id = GetThreadId(threading.currentThread()) if thread_id != curr_thread_id: try: return getCustomFrame( thread_id, frame_id ) #I.e.: thread_id could be a stackless frame id + thread_id. except: pass raise VariableError( "findFrame: must execute on same thread (%s != %s)" % (thread_id, curr_thread_id)) lookingFor = int(frame_id) if AdditionalFramesContainer.additional_frames: if DictContains(AdditionalFramesContainer.additional_frames, thread_id): frame = AdditionalFramesContainer.additional_frames[ thread_id].get(lookingFor) if frame is not None: return frame curFrame = GetFrame() if frame_id == "*": return curFrame # any frame is specified with "*" frameFound = None for frame in iterFrames(curFrame): if lookingFor == id(frame): frameFound = frame del frame break del frame #Important: python can hold a reference to the frame from the current context #if an exception is raised, so, if we don't explicitly add those deletes #we might have those variables living much more than we'd want to. #I.e.: sys.exc_info holding reference to frame that raises exception (so, other places #need to call sys.exc_clear()) del curFrame if frameFound is None: msgFrames = '' i = 0 for frame in iterFrames(GetFrame()): i += 1 msgFrames += str(id(frame)) if i % 5 == 0: msgFrames += '\n' else: msgFrames += ' - ' errMsg = '''findFrame: frame not found. Looking for thread_id:%s, frame_id:%s Current thread_id:%s, available frames: %s\n ''' % (thread_id, lookingFor, curr_thread_id, msgFrames) sys.stderr.write(errMsg) return None return frameFound except: import traceback traceback.print_exc() return None
def findFrame(thread_id, frame_id): """ returns a frame on the thread that has a given frame_id """ try: curr_thread_id = GetThreadId(threading.currentThread()) if thread_id != curr_thread_id : try: return getCustomFrame(thread_id, frame_id) #I.e.: thread_id could be a stackless frame id + thread_id. except: pass raise VariableError("findFrame: must execute on same thread (%s != %s)" % (thread_id, curr_thread_id)) lookingFor = int(frame_id) if AdditionalFramesContainer.additional_frames: if DictContains(AdditionalFramesContainer.additional_frames, thread_id): frame = AdditionalFramesContainer.additional_frames[thread_id].get(lookingFor) if frame is not None: return frame curFrame = GetFrame() if frame_id == "*": return curFrame # any frame is specified with "*" frameFound = None for frame in iterFrames(curFrame): if lookingFor == id(frame): frameFound = frame del frame break del frame #Important: python can hold a reference to the frame from the current context #if an exception is raised, so, if we don't explicitly add those deletes #we might have those variables living much more than we'd want to. #I.e.: sys.exc_info holding reference to frame that raises exception (so, other places #need to call sys.exc_clear()) del curFrame if frameFound is None: msgFrames = '' i = 0 for frame in iterFrames(GetFrame()): i += 1 msgFrames += str(id(frame)) if i % 5 == 0: msgFrames += '\n' else: msgFrames += ' - ' errMsg = '''findFrame: frame not found. Looking for thread_id:%s, frame_id:%s Current thread_id:%s, available frames: %s\n ''' % (thread_id, lookingFor, curr_thread_id, msgFrames) sys.stderr.write(errMsg) return None return frameFound except: import traceback traceback.print_exc() return None