def send_command(self, cmd): if isinstance(cmd, ToplevelCommand) and cmd.command in ("Run", "Debug", "Reset"): self.kill_current_process() self._start_new_process(cmd) self._proc.stdin.write(serialize_message(cmd) + "\n") self._proc.stdin.flush() return True
def send_message(self, message_type, **kwargs): kwargs["message_type"] = message_type if "cwd" not in kwargs: kwargs["cwd"] = os.getcwd() self._original_stdout.write(serialize_message(kwargs) + "\n") self._original_stdout.flush()
def _forward_incoming_command(self, msg): msg_str = serialize_message(msg, 1024) for line in msg_str.splitlines(keepends=True): self._proc.stdin.write(line) self._proc.stdin.flush() self._proc.stdin.write("\n")
def send_message(self, msg): if "cwd" not in msg: msg["cwd"] = os.getcwd() if isinstance(msg, ToplevelResponse) and "globals" not in msg: msg["globals"] = self.export_globals() self._original_stdout.write(serialize_message(msg) + "\n") self._original_stdout.flush()
def __init__(self, args): try: self._interpreter = self._resolve_executable(args["interpreter"]) self._connection = self._create_connection() except ConnectionFailedException as e: text = "\n" + str(e) + "\n" msg = BackendEvent(event_type="ProgramOutput", stream_name="stderr", data=text) sys.stdout.write(serialize_message(msg) + "\n") sys.stdout.flush() return MicroPythonBackend.__init__(self, None, args)
def send_command(self, cmd): with self._state_lock: if isinstance(cmd, ActionCommand): self._current_pause_msg = None if (isinstance(cmd, ToplevelCommand) and cmd.command in ("Run", "Debug", "Reset")): self._kill_current_process() self._start_new_process(cmd) self._proc.stdin.write((serialize_message(cmd) + "\n").encode(COMMUNICATION_ENCODING)) self._proc.stdin.flush() # required for Python 3.1 debug("sent a command: %s", cmd)
def send_message(self, msg: MessageFromBackend) -> None: sys.stdout.flush() if isinstance(msg, ToplevelResponse): if "cwd" not in msg: msg["cwd"] = os.getcwd() if "globals" not in msg: msg["globals"] = self.export_globals() self._original_stdout.write(serialize_message(msg) + "\n") self._original_stdout.flush() if isinstance(msg, ToplevelResponse): self._check_load_jedi()
def __init__(self, mp_executable, api_stubs_path, cwd=None): try: self._mp_executable = self._resolve_executable(mp_executable) self._connection = self._create_connection() except ConnectionFailedException as e: text = "\n" + str(e) + "\n" msg = BackendEvent(event_type="ProgramOutput", stream_name="stderr", data=text) sys.stdout.write(serialize_message(msg) + "\n") sys.stdout.flush() return super().__init__(None, api_stubs_path, cwd=cwd)
def send_command(self, cmd): if not (isinstance(cmd, InlineCommand) and cmd.command == "tkupdate"): debug("Proxy: Sending command: %s", cmd) with self._state_lock: if (isinstance(cmd, ToplevelCommand) or isinstance(cmd, DebuggerCommand) or isinstance(cmd, InputSubmission)): self._set_state("running") if isinstance(cmd, ToplevelCommand) and cmd.command in ("Run", "Debug", "Reset"): self.kill_current_process() self._start_new_process(cmd) self._proc.stdin.write(serialize_message(cmd) + "\n") self._proc.stdin.flush() if not (hasattr(cmd, "command") and cmd.command == "tkupdate"): debug("BackendProxy: sent a command in state %s: %s", self._state, cmd)
elif args["port"] == "webrepl": connection = WebReplConnection(args["url"], args["password"]) else: from thonny.plugins.micropython.serial_connection import ( DifficultSerialConnection, SerialConnection, ) connection = SerialConnection(args["port"], BAUDRATE) # connection = DifficultSerialConnection(args["port"], BAUDRATE) if "circuitpython" in args.get("proxy_class", "").lower(): from thonny.plugins.circuitpython.cp_backend import CircuitPythonBackend backend = CircuitPythonBackend(connection, clean=args["clean"], args=args) else: backend = BareMetalMicroPythonBackend(connection, clean=args["clean"], args=args) except ConnectionFailedException as e: text = "\n" + str(e) + "\n" msg = BackendEvent(event_type="ProgramOutput", stream_name="stderr", data=text) sys.stdout.write(serialize_message(msg) + "\n") sys.stdout.flush()
def send_message(self, msg: MessageFromBackend) -> None: sys.stdout.write(serialize_message(msg) + "\n") sys.stdout.flush()
def send_message(self, msg): if "cwd" not in msg: msg["cwd"] = self._cwd sys.stdout.write(serialize_message(msg) + "\n") sys.stdout.flush()
def _send_msg(self, msg): self._proc.stdin.write(serialize_message(msg) + "\n") self._proc.stdin.flush()
def _forward_incoming_command(self, msg): self._proc.stdin.write(serialize_message(msg) + "\n")