import logging import inspect tracing_logger = logging.getLogger() tracing_logger.addHandler(logging.StreamHandler()) def log_info(frame_info): tracing_logger.warning("currentThread overridden with None: %s", inspect.getframeinfo(frame_info)) def trace_currentThread(cur_frame, event, arg): if event == 'call': return trace_currentThread #Trace new scope being entered elif event == 'exception': return None #Don't need to trace else: import inspect if cur_frame.f_locals.has_key('currentThread'): if cur_frame.f_locals['currentThread'] == None: log_info(cur_frame) elif cur_frame.f_locals.has_key('threading'): if cur_frame.f_locals['threading'].currentThread == None: log_info(cur_frame) elif cur_frame.f_globals.has_key('currentThread'): if cur_frame.f_globals['currentThread'] == None: log_info(cur_frame) elif cur_frame.f_globals.has_key('threading'): if cur_frame.f_globals['threading'].currentThread == None: log_info(cur_frame) return None #Since found error, turn off tracing def test(): currentThread = 'A' currentThread = None if __name__ == '__main__': import sys sys.settrace(trace_currentThread) test()