-
Notifications
You must be signed in to change notification settings - Fork 1k
uasyncio: core.py frozen results in OverflowError: overflow converting long int to machine word #177
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
Comments
If you want to have this resolved, you will need to provide a minimal testcase to reproduce this. |
For my case, the delay variable becomes 1045220558000 which is far beyond the sys.maxint. Testcase:
and call it with the value from above. I guess this is a bug within the uasyncio core.py? |
Why actually int(2147483647 + 1) does give me 2147483648? shouldn't it give some overflowed value? for now I assume that 2147483647 is the sys.maxint for micropython, it is at least for python2.7 on windows. |
In ms that's about 33 years. Why is your code scheduling something so far in the future?
No, Python has arbitrary sized integers so there is no overflow in Python scripts. |
It is a reminder for my 65. birthday 🍰 No, I guess there is a problem with the uasyncio after make it frozen. I just created two tasks and call open_connection(). How to fix this? Am I the first one freezing uasyncio?
Then the time.ticks_add function needs to be changed? Or is 33 adding 33 years as ticks a minor usecase? |
Please provide your full test case that breaks, ideally stripped down to a minimal script that still exibits the same problem.
While there's no overflow in scripts, there can still be overflow in the C code for certain operations. In this case 33 years in milliseconds is a number that ticks_diff is not designed to handle. Note that having such a large dynamic range, from ms to years, is difficult to achieve within fixed memory requirements. |
No, I froze not just uasyncio, but full web stack and an application built on it, see |
No. But you may need to change the way you use it.
uasyncio doesn't work with years. It's a real-time scheduling system. Read the docs for how ticks_add() works. If you want to create an alarm in years, you will need to create an alarm which will work like that, uasyncio doesn't support creation of alarms, just scheduling of realtime tasks. |
Main function:
Here are my modules. I changed the following: core.py added a print of the delay value
init.py changed the open_connection function to allow for tcp connection
Freeze this files, and run this tcp server in a python notebook:
|
@riegaz Are you confusing integers with ticks values? Integers have arbitrary precision: arithmetic operators produce expected values regardless of magnitude. Ticks values use modular arithmetic to constrain them to a single machine word. This is done for reasons of efficiency but necessarily limits their dynamic range. Long duration delays may readily be implemented e.g. by using As a personal opinion I think a test case is more likely to command the attention of the maintainers if raised against the standard official version of the library. |
I was just joking about the 33 years. For me I just found a problem arising after creating a frozen module out of uasyncio. I do not want to abuse the uasyncio for an alarm clock.
I only moved the |
@peterhinch So I just downloaded the fresh uasyncio and moved it to modules. uasyncio / init.py I ran the same code I provided above. The result is as posted in my first post:
|
@riegaz you need to provide more information, and a proper reproducible test case. What is main.py and main1.py? |
Here is my minimal testcase: board: esp8266 (ESP-12S) I set up building environment like here: http://akshaim.github.io/IoT/MicroPython_ESP8266/MP_ESP_101.html Create the following folder within esp-open-sdk/micropython/esp8266/modules I added logging.py to the modules folder as well Here is the firmware I build: main.py
which fails with this message:
Another testcase: https://github.com/peterhinch/micropython-async/blob/master/aqtest.py |
What implementation of uasyncio/queues.py And what about collections.deque, since that's needed be the default queues.py? Running your main() code above works ok for me using a dummy Queue class. |
Sorry, I forgot to mention collections.deque. I used everything as is from micropython-lib. I changed nothing. |
@riegaz thanks for providing that info, I think I found the problem: the freezing of floats was recently broken by micropython/micropython@ec53460 and I've now fixed that in micropython/micropython@88c51c3 . It's good that you picked this problem up otherwise it may have made it into the upcoming v1.9 release, so thanks for submitting this issue! Please can you try the latest MicroPython code to see if your code now works? |
@dpgeorge I can confirm that it works. Thanks a lot! |
Thanks for figuring it out everyone. |
I just created the following files within the modules folder:
uasyncio / init.py
core.py
queues.py
collections / deque.py
When I then run my code I get the following error:
This is the function:
The text was updated successfully, but these errors were encountered: