def log_new_thread(global_debugger): t = threadingCurrentThread() event_time = cur_time() - global_debugger.thread_analyser.start_time send_message("threading_event", event_time, t.getName(), GetThreadId(t), "thread", "start", "code_name", 0, None, parent=GetThreadId(t))
def suspend_django(py_db_frame, mainDebugger, thread, frame, cmd=CMD_SET_BREAK): frame = DjangoTemplateFrame(frame) if frame.f_lineno is None: return None #try: # if thread.additionalInfo.filename == frame.f_code.co_filename and thread.additionalInfo.line == frame.f_lineno: # return None # don't stay twice on the same line #except AttributeError: # pass pydevd_vars.addAdditionalFrameById(GetThreadId(thread), {id(frame): frame}) py_db_frame.setSuspend(thread, cmd) thread.additionalInfo.suspend_type = DJANGO_SUSPEND thread.additionalInfo.filename = frame.f_code.co_filename thread.additionalInfo.line = frame.f_lineno return frame
def _suspend_jinja2(pydb, thread, frame, cmd=CMD_SET_BREAK): frame = Jinja2TemplateFrame(frame) if frame.f_lineno is None: return None pydevd_vars.addAdditionalFrameById(GetThreadId(thread), {id(frame): frame}) pydb.setSuspend(thread, cmd) thread.additionalInfo.suspend_type = JINJA2_SUSPEND thread.additionalInfo.filename = frame.f_code.co_filename thread.additionalInfo.line = frame.f_lineno return frame
def _suspend_jinja2(pydb, thread, frame, cmd=CMD_SET_BREAK, message=None): frame = Jinja2TemplateFrame(frame) if frame.f_lineno is None: return None pydevd_vars.addAdditionalFrameById(GetThreadId(thread), {id(frame): frame}) pydb.setSuspend(thread, cmd) thread.additionalInfo.suspend_type = JINJA2_SUSPEND thread.additionalInfo.filename = frame.f_code.co_filename thread.additionalInfo.line = frame.f_lineno if cmd == CMD_ADD_EXCEPTION_BREAK: # send exception name as message thread.additionalInfo.message = message return frame
def log_event(self, frame): write_log = False self_obj = None if DictContains(frame.f_locals, "self"): self_obj = frame.f_locals["self"] if isinstance(self_obj, threading.Thread) or self_obj.__class__ == ObjectWrapper: write_log = True try: if write_log: t = threadingCurrentThread() back = frame.f_back if not back: return name, back_base = pydevd_file_utils.GetFilenameAndBase(back) event_time = cur_time() - self.start_time method_name = frame.f_code.co_name if isinstance(self_obj, threading.Thread) and method_name in THREAD_METHODS: if back_base not in DONT_TRACE_THREADING or \ (method_name in INNER_METHODS and back_base in INNER_FILES): thread_id = GetThreadId(self_obj) name = self_obj.getName() real_method = frame.f_code.co_name if real_method == "_stop": # TODO: Python 2 if back_base in INNER_FILES and \ back.f_code.co_name == "_wait_for_tstate_lock": back = back.f_back.f_back real_method = "stop" elif real_method == "join": # join called in the current thread, not in self object thread_id = GetThreadId(t) name = t.getName() parent = None if real_method in ("start", "stop"): parent = GetThreadId(t) send_message("threading_event", event_time, name, thread_id, "thread", real_method, back.f_code.co_filename, back.f_lineno, back, parent=parent) # print(event_time, self_obj.getName(), thread_id, "thread", # real_method, back.f_code.co_filename, back.f_lineno) if self_obj.__class__ == ObjectWrapper: if back_base in DONT_TRACE_THREADING: # do not trace methods called from threading return _, back_back_base = pydevd_file_utils.GetFilenameAndBase(back.f_back) back = back.f_back if back_back_base in DONT_TRACE_THREADING: # back_back_base is the file, where the method was called froms return if method_name == "__init__": send_message("threading_event", event_time, t.getName(), GetThreadId(t), "lock", method_name, back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(frame.f_locals["self"]))) if DictContains(frame.f_locals, "attr") and \ (frame.f_locals["attr"] in LOCK_METHODS or frame.f_locals["attr"] in QUEUE_METHODS): real_method = frame.f_locals["attr"] if method_name == "call_begin": real_method += "_begin" elif method_name == "call_end": real_method += "_end" else: return if real_method == "release_end": # do not log release end. Maybe use it later return send_message("threading_event", event_time, t.getName(), GetThreadId(t), "lock", real_method, back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(self_obj))) if real_method in ("put_end", "get_end"): # fake release for queue, cause we don't call it directly send_message("threading_event", event_time, t.getName(), GetThreadId(t), "lock", "release", back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(self_obj))) # print(event_time, t.getName(), GetThreadId(t), "lock", # real_method, back.f_code.co_filename, back.f_lineno) except Exception: traceback.print_exc()