def test_find_thread(): from _pydevd_bundle.pydevd_constants import get_current_thread_id assert pydevd_find_thread_by_id('123') is None assert pydevd_find_thread_by_id( get_current_thread_id( threading.current_thread())) is threading.current_thread()
def request_suspend_thread(self, py_db, thread_id='*'): # Yes, thread suspend is done at this point, not through an internal command. threads = [] suspend_all = thread_id.strip() == '*' if suspend_all: threads = pydevd_utils.get_non_pydevd_threads() elif thread_id.startswith('__frame__:'): sys.stderr.write("Can't suspend tasklet: %s\n" % (thread_id,)) else: threads = [pydevd_find_thread_by_id(thread_id)] for t in threads: if t is None: continue py_db.set_suspend( t, CMD_THREAD_SUSPEND, suspend_other_threads=suspend_all, is_pause=True, ) # Break here (even if it's suspend all) as py_db.set_suspend will # take care of suspending other threads. break
def request_set_next(self, py_db, seq, thread_id, set_next_cmd_id, line, func_name): t = pydevd_find_thread_by_id(thread_id) if t: int_cmd = InternalSetNextStatementThread(thread_id, set_next_cmd_id, line, func_name, seq=seq) py_db.post_internal_command(int_cmd, thread_id) elif thread_id.startswith('__frame__:'): sys.stderr.write("Can't set next statement in tasklet: %s\n" % (thread_id,))
def request_smart_step_into(self, py_db, seq, thread_id, offset, child_offset): t = pydevd_find_thread_by_id(thread_id) if t: py_db.post_method_as_internal_command( thread_id, internal_smart_step_into, thread_id, offset, child_offset, set_additional_thread_info=set_additional_thread_info) elif thread_id.startswith('__frame__:'): sys.stderr.write("Can't set next statement in tasklet: %s\n" % (thread_id,))
def make_thread_suspend_single_notification(self, py_db, thread_id, stop_reason): exc_desc = None exc_name = None thread = pydevd_find_thread_by_id(thread_id) info = set_additional_thread_info(thread) preserve_focus_hint = False if stop_reason in self._STEP_REASONS: if info.pydev_original_step_cmd == CMD_STOP_ON_START: # Just to make sure that's not set as the original reason anymore. info.pydev_original_step_cmd = -1 stop_reason = 'entry' else: stop_reason = 'step' elif stop_reason in self._EXCEPTION_REASONS: stop_reason = 'exception' elif stop_reason == CMD_SET_BREAK: stop_reason = 'breakpoint' elif stop_reason == CMD_SET_FUNCTION_BREAK: stop_reason = 'function breakpoint' elif stop_reason == CMD_SET_NEXT_STATEMENT: stop_reason = 'goto' else: stop_reason = 'pause' preserve_focus_hint = True if stop_reason == 'exception': exception_info_response = build_exception_info_response( py_db, thread_id, -1, set_additional_thread_info, self._iter_visible_frames_info, max_frames=-1) exception_info_response exc_name = exception_info_response.body.exceptionId exc_desc = exception_info_response.body.description body = pydevd_schema.StoppedEventBody( reason=stop_reason, description=exc_desc, threadId=thread_id, text=exc_name, allThreadsStopped=True, preserveFocusHint=preserve_focus_hint, ) event = pydevd_schema.StoppedEvent(body) return NetCommand(CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION, 0, event, is_json=True)
def request_step(self, py_db, thread_id, step_cmd_id): t = pydevd_find_thread_by_id(thread_id) if t: py_db.post_method_as_internal_command( thread_id, internal_step_in_thread, thread_id, step_cmd_id, set_additional_thread_info=set_additional_thread_info, ) elif thread_id.startswith('__frame__:'): sys.stderr.write("Can't make tasklet step command: %s\n" % (thread_id,))
def cmd_get_exception_details(self, py_db, cmd_id, seq, text): thread_id = text t = pydevd_find_thread_by_id(thread_id) frame = None if t and not getattr(t, 'pydev_do_not_trace', None): additional_info = set_additional_thread_info(t) frame = additional_info.get_topmost_frame(t) try: return py_db.cmd_factory.make_get_exception_details_message(py_db, seq, thread_id, frame) finally: frame = None t = None
def request_set_next(self, py_db, seq, thread_id, set_next_cmd_id, original_filename, line, func_name): ''' :param Optional[str] original_filename: If available, the filename may be source translated, otherwise no translation will take place (the set next just needs the line afterwards as it executes locally, but for the Jupyter integration, the source mapping may change the actual lines and not only the filename). ''' t = pydevd_find_thread_by_id(thread_id) if t: if original_filename is not None: translated_filename = self.filename_to_server( original_filename) # Apply user path mapping. pydev_log.debug( 'Set next (after path translation) in: %s line: %s', translated_filename, line) func_name = self.to_str(func_name) assert translated_filename.__class__ == str # i.e.: bytes on py2 and str on py3 assert func_name.__class__ == str # i.e.: bytes on py2 and str on py3 # Apply source mapping (i.e.: ipython). _source_mapped_filename, new_line, multi_mapping_applied = py_db.source_mapping.map_to_server( translated_filename, line) if multi_mapping_applied: pydev_log.debug( 'Set next (after source mapping) in: %s line: %s', translated_filename, line) line = new_line int_cmd = InternalSetNextStatementThread(thread_id, set_next_cmd_id, line, func_name, seq=seq) py_db.post_internal_command(int_cmd, thread_id) elif thread_id.startswith('__frame__:'): sys.stderr.write("Can't set next statement in tasklet: %s\n" % (thread_id, ))