← index #6440Issue #2621
Off-topic · high · value 1.055
QUERY · ISSUE

Implement exit() to exit for ./micropython shell

openby nanjekyejoannahopened 2020-09-13updated 2024-09-29
enhancementport-unix

I know that currently CTRL-D exits the shell.

For consistency with other python shells i.e CPython, let us implement exit() as an option to also exit the shell.

If this sounds good, i will track this for myself so that I can implement this as part of google season of docs.

CANDIDATE · ISSUE

Context manager __exit__() not called in generator which does not run to completion

closedby peterhinchopened 2016-11-12updated 2025-03-03
proposed-close

This occurs when a generator does not run to completion e.g. one yielding an infinite set. The following works in cPython but not in MicroPython:

class foo(object):
    def __enter__(self):
        print('Enter')
    def __exit__(self, *args):
        print('Exit')

def bar(x):
    with foo():
        while True:
            x += 1
            yield x

def func():
    g = bar(0)
    for _ in range(3):
        print(next(g))

func()

MicroPython:

[adminpete@axolotl]: ~
$ unix/upython
MicroPython v1.8.1-794-g29f3f84-dirty on 2016-11-10; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import rats10
Enter
1
2
3
>>> 

cPython

$ python3
Python 3.4.3 (default, Sep 14 2016, 12:36:27) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rats10
Enter
1
2
3
Exit
>>> 

A similar effect can be seen in try...finally blocks. In cPython the finally block runs on exit from the REPL, in MicroPython never. In my view the context manager issue is the more serious one.

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