← index #4971Issue #2306
Related · high · value 0.118
QUERY · ISSUE

RFC: "REPL interact" as easier to implement debugger?

openby andrewleechopened 2019-08-03updated 2019-08-06

Would it be possible/easy to create a micropython.interact() function that would break to repl in the current scope, with a continue function that can be run in said repl to resume the program flow after you've investigated what's going on?

This could be used like a hard coded breakpoint, say if your code detects an error it will throw you into the repl at that point so you can inspect what's going on.

CANDIDATE · ISSUE

Feature suggestion; Triggering Repl in handler decorator

closedby cefnopened 2016-08-09updated 2017-06-14

A very low-priority feature request;

Trying to approach 'debugging' some code intended for Micropython on the ESP8266. I was thinking to run the code in Python3 on my laptop with stubs emulating the ESP8266 to prove functionality, then transfer to the ESP8266 module when I want to prove it for real, assuming that I have eliminated any major bugs and allowing final tweaks.

However, another approach occurred to me, though it may be beyond my skills with micropython currently.

Alternative - an Interactive REPL decorator

In the absence of pdb support in micropython, it might be useful to be able to decorate arbitrary handlers so that the REPL is launched with access to the args and kwargs when the decorated function is called.

The user of the interactive prompt must then 'return' a function for execution to continue, (although a method based on 'raise' passing back the function might be more appropriate for interactively quitting since 'return' is invalid in a REPL).

Stock functions could be provided in locals (e.g. operations 'raising' functions to return fixed values, operations 'raising' a function to defer to the original handler). Importantly, all local values could be inspected and functions 'test-run' interactively in the context to see what they will do.

Does this make any sense at all? Is there a core problem with asynchrony which makes this 'hiding' of a REPL inside a function actually impossible?

How could this be approached? I note there is support in python 3 via https://docs.python.org/3/library/code.html but not sure if this applies to micropython or how to get access to the REPL 'tty' streams elegantly to wire in an interactive interpreter when the decorator is invoked.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied