except KeyboardInterrupt
not working in 3rd-party Micropython port (PyCom)
#17396
-
Hi internet, I'm sorry if this is the wrong forum, although I am kind of out of luck at this point. I have a bunch of old devices of the brand PyCom, a company which has now shut down. However, it uses a custom MicroPython port and I therefore thought that this would be the second best place to post (since the PyCom forums have been shut down). I have this minimal working example of a try:
while True:
password = input("password please")
if password == "test":
print("done!")
break
except KeyboardInterrupt:
print("heh, don't you think i knew?") This is the only content in the password pleaseTraceback (most recent call last):
File "main.py", line 6, in <module>
KeyboardInterrupt:
Pycom MicroPython 1.20.2.r6 [v1.11-c5a0a97] on 2021-10-28; GPy with ESP32
Pybytes Version: 1.7.1
Type "help()" for more information. (note "password please" at the beginning of the line) I would love to have used // Whether to provide the mp_kbd_exception object, and micropython.kbd_intr function
#ifndef MICROPY_KBD_EXCEPTION
#define MICROPY_KBD_EXCEPTION (0)
#endif I tried some of the fixes suggested in this, but no luck. It looks like PyCom do not raise // Prefer to raise KeyboardInterrupt asynchronously (from signal or interrupt
// handler) - if supported by a particular port.
#ifndef MICROPY_ASYNC_KBD_INTR
#define MICROPY_ASYNC_KBD_INTR (0)
#endif I am not expecting any advanced support from this forum, since this is a custom MicroPython port, but since the company is closed, I have no idea where else to ask. I guess a relevant question is if this code works in standard MicroPython? If it does, where can I look next in order to solve the issue? Many thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I have a few Pycom boards and am able to build a firmware, so I can look into it. Which board do you use? |
Beta Was this translation helpful? Give feedback.
-
For the definition of The code snippet works in standard MicroPython. Tested on a RP2 board. |
Beta Was this translation helpful? Give feedback.
-
Hi @robert-hh thank you so much for your answer. I was indeed wrong. I used |
Beta Was this translation helpful? Give feedback.
For the definition of
MICROPY_KBD_EXCEPTION
you have to look into esp32/mpconfigport.h as well. And there is reads:#define MICROPY_KBD_EXCEPTION (1)
https://github.com/pycom/pycom-micropython-sigfox/blob/a37510c092bcec00671c924accb97dcdfa2f4b5d/esp32/mpconfigport.h#L129
The code snippet works in standard MicroPython. Tested on a RP2 board.
Places to look for:
lib/mp_readline/readline.c, functions readline() and readline_process_char().
mods/machuart.c, function UARTRxCallback() and uart_rx_char()
lib/utils/pyexec.c, function pyexec_friendly_repl()
calls to mp_hal_set_interrupt_char(). mp_hal_set_interrupt_char(-1) disables keyboard interrupt.