sys.atexit() unavailable ?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

sys.atexit() unavailable ?

Post by pidou46 » Wed May 12, 2021 4:37 pm

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 ?
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: sys.atexit() unavailable ?

Post by stijn » Wed May 12, 2021 6:11 pm

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.

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: sys.atexit() unavailable ?

Post by pidou46 » Wed May 12, 2021 7:57 pm

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 ?
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: sys.atexit() unavailable ?

Post by stijn » Thu May 13, 2021 6:14 am

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.

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: sys.atexit() unavailable ?

Post by pidou46 » Thu May 13, 2021 7:11 am

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.
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: sys.atexit() unavailable ?

Post by stijn » Thu May 13, 2021 1:29 pm

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

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: sys.atexit() unavailable ?

Post by Roberthh » Thu May 13, 2021 4:38 pm

It is there right at the beginning of the library reference section.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: sys.atexit() unavailable ?

Post by scruss » Sat Jul 30, 2022 5:19 pm

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

Post Reply