JetBrains / intellij-micropython

Plugin for MicroPython devices in PyCharm and IntelliJ
https://plugins.jetbrains.com/plugin/9777-micropython
Apache License 2.0
513 stars 106 forks source link

KeyboardInterrupt on with "Open REPL on success" #312

Closed lukaskremla closed 3 months ago

lukaskremla commented 3 months ago

After the recent update got REPL working I have ran into the following issue:

I am working with an ESP32 S2 through the ESP8266 device type in the MicroPython settings and I experience the following behavior both on Mac and on Windows.

When toggling the open REPL on success is done, the following happens: " Device path /dev/cu.usbserial-10 Quit: Ctrl+] | Stop program: Ctrl+C | Reset: Ctrl+D Type 'help()' (without the quotes) then press ENTER. Traceback (most recent call last): File "main.py", line 49, in KeyboardInterrupt: MicroPython v1.24.0-preview.82.g95c19e05f on 2024-07-01; Generic ESP32S2 N8R2 module with ESP32S2 Type "help()" for more information. "

The traceback might lead to all files that are ran from main, regardless of what is in them. Even a simple while true loop with sleep(2) inside it will be listed, and the errors will always link to the last line of the code inside of the file.

However, REPL does works, either restarting the connection with the buttons on the left side of REPL or pressing the ESP32 Reset button will lead to the REPL starting properly with no errors: " Device path /dev/cu.usbserial-10 Quit: Ctrl+] | Stop program: Ctrl+C | Reset: Ctrl+D Type 'help()' (without the quotes) then press ENTER.

"

I have tried taking out the script responsible for the REPL connection and I ran it on it's own, trying to achieve the built in behavior this way. I made a Python configuration, added before launch task of flashing the device and configured it to open the REPL file after. This would result in the same problem if ran right after flashing, if I added a timer before it to delay the connection it would work well.

My guess is that the REPL connection attempt is made too soon after flashing and there is some conflict on flash and REPL connecting at the same time, but adding a timer in the file leads to me not being able to see what the device I am working on is printing right after start, because the connection is delayed.

I have tried a configuration that would run pySerial after flashing instead of the REPL file, which works without a problem.

The bug is present in the latest 1.4.4 MicroPython plugin version on the following build of PyCharm: "Build #PY-241.18034.82, built on June 24, 2024" for MacOS M2.

elmot commented 3 months ago

Most probably duplicate of #283

Workaround is to click Ctrl-D (Command-D probably on mac) in REPL window