Skip to content

time.monotonic() returns no fraction of seconds after *long* runtime. #5411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ThomasAtBBTF opened this issue Sep 30, 2021 · 2 comments
Closed
Labels
Milestone

Comments

@ThomasAtBBTF
Copy link

CircuitPython version

Adafruit CircuitPython 5.4.0  LoC BeR M4 base board with samd51g19

Code/REPL

import time
time.monotonic()
# in code and the command line, the fraction of seconds was always .0

Behavior

I did observe this behavior last night on a device that was running for many days.
Note: that also after breaking the code with ctrl-c and importing time
and entering time.monotonic() in the command line, the fraction of seconds was always .0
Only after microcontroller.reset() this behavior stopped.

I will try to reproduce this with other controllers and CP 7.0.
But it will take days until I have a result ....

Description

No response

Additional information

No response

@dhalbert
Copy link
Collaborator

This is a known problem with time.monotonic(), because of the low precision of floats (5-6 digits). We recommend you use time.monotonic_ns(), if you board supports it (must have longints). Or, if it works for you, you can use supervisor.ticks_ms(), which wrap but keep their precision.

See #342 (comment) for some background on the precision issue.

@dhalbert dhalbert added this to the Support milestone Sep 30, 2021
@ThomasAtBBTF
Copy link
Author

Ok, thank you taking a look at this so quickly and for the explanation.
It would be helpful if is this information would be available at:
https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/

Also a possibility to programmatically reset to time.monotonic "0" would be helpful, as this situation can be detected quite easily, now that I know how,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants