Page 1 of 1

sys.atexit() unavailable ?

Posted: Wed May 12, 2021 4:37 pm
by pidou46
Hello,

In the doc: http://docs.micropython.org/en/latest/library/usys.html
I found information about the sys.atexit() function but I'm not able to import it with the latest firmware:

Code: Select all

MicroPython v1.15 on 2021-04-29; ESP32 module with ESP32
Type "help()" for more information.
>>> from usys import atexit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: can't import name atexit
>>> import usys
>>> usys.atexit()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'atexit'
>>>
Should I open an issue, or did I miss something ?

Re: sys.atexit() unavailable ?

Posted: Wed May 12, 2021 6:11 pm
by stijn
It's an optional feature not enabled for all ports. See https://github.com/micropython/micropython/pull/4978 for some discussion. Can be built in custom firmware by passing -DMICROPY_PY_SYS_ATEXIT=1 to the compiler.

Re: sys.atexit() unavailable ?

Posted: Wed May 12, 2021 7:57 pm
by pidou46
Thank's Stijn,

So if understand it right this statement in the doc : "This function is a MicroPython extension" mean that this function is not included in the firmware right ?

Re: sys.atexit() unavailable ?

Posted: Thu May 13, 2021 6:14 am
by stijn
No that particular sentence means that this is not a standard Python function, but something specific to MicroPython. Other Python implementations (CPython, ...) do not have a sys.atexit() function at all.

Re: sys.atexit() unavailable ?

Posted: Thu May 13, 2021 7:11 am
by pidou46
Ok, so it may be a good idea to mention in the doc that this function is not included in the firmware, isn't it?
I will create an issue on github.

Re: sys.atexit() unavailable ?

Posted: Thu May 13, 2021 1:29 pm
by stijn
I always assumed somewhere in the intro of the docs there's a note saying that not all functions are available on all ports. If not, that's what should be added: there are like 100 configurable features, we can't possible go mention for each one of them that it might not be in a particular firmware :D

Re: sys.atexit() unavailable ?

Posted: Thu May 13, 2021 4:38 pm
by Roberthh
It is there right at the beginning of the library reference section.

Re: sys.atexit() unavailable ?

Posted: Sat Jul 30, 2022 5:19 pm
by scruss
It would be really nice if this warning header was at the start of every library doc, because I just spent far too long fighting with a sys.atexit() that wasn't there in the RP2 port