Skip to content
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

Kivy crashes after setting system clock back in time #3952

Open
Bounder opened this issue Jan 29, 2016 · 7 comments
Open

Kivy crashes after setting system clock back in time #3952

Bounder opened this issue Jan 29, 2016 · 7 comments
Labels
Component: core-app app, clock, config, inspector, logger, resources, modules, clock, base.py Priority: High Should be fixed ASAP Type: Bug A bug or something not working as intended

Comments

@Bounder
Copy link
Contributor

Bounder commented Jan 29, 2016

I'm currently developing an app on OSX (Version 10.11.3) which displays a analog clock, so i'm testing how the clock updates when the system time is adjusted for summer/winter time. I found out when adjusting the system time by adding an hour fire's all events, which is inconvenient but not a problem for me. However setting the system time back with one hour crashes Kivy. I also tested this in an unrelated Kivy app which also crashed, so I think this problem is universal for Kivy on OSX.

I did not had the time yet to determine if this problem exists an all platforms or just OSX. It would be nice to know if this is the case. Attached to this issue you'll find the stack trace I get when aborting the debug session.

 Traceback (most recent call last):
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/app.py", line 824, in run
     runTouchApp()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/base.py", line 487, in runTouchApp
     EventLoop.window.mainloop()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/core/window/window_sdl2.py", line 539, in mainloop
     self._mainloop()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/core/window/window_sdl2.py", line 300, in _mainloop
     EventLoop.idle()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/base.py", line 327, in idle
     Clock.tick()
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/clock.py", line 461, in tick
     usleep(1000000 * (sleeptime - sleep_undershoot))
   File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/clock.py", line 267, in usleep
     _default_sleep(microseconds / 1000000.)
 KeyboardInterrupt
@dessant
Copy link
Contributor

dessant commented Jan 29, 2016

Thanks for the report. There was a pr which fixes this in some cases: #2906.

It didn't always work, and produced this exception (#3797):

I/python (14014): File "...main.py", line 18, in
I/python (14014): File ".../kivy/app.py", line 319, in
I/python (14014): File ".../kivy/base.py", line 29, in
I/python (14014): File ".../kivy/clock.py", line 278, in
I/python (14014): File ".../kivy/clock.py", line 258, in libc_clock_gettime_wrapper
I/python (14014): File ".../python2.7/ctypes/__init_.py", line 369, in getattr
I/python (14014): File ".../ctypes/init.py", line 374, in getitem
I/python (14014): AttributeError: undefined symbol: clock_gettime

Currently we fall back to the old implementation when there is an exception:
cf31ef7

@matham pointed out this solution, it would be cross-platform, but it only applies to python 3:
https://www.python.org/dev/peps/pep-0418/#time-monotonic

@dessant dessant added the Priority: High Should be fixed ASAP label Jan 29, 2016
@dessant dessant added this to the 2.0.0 milestone Jan 29, 2016
@Bounder
Copy link
Contributor Author

Bounder commented Feb 1, 2016

Thanks for the quick answer. I updated my Kivy environment to version 1.9.1-dev0 / Python 2.7.10 and I found out Kivy still hangs. After debugging I saw it went directly to the fallback implementation. After some googling found out that OS X El Capitan moved the libc library, they can now be accessed using the following path:/usr/lib/libc.dylib instead of libc.dylib , however after changing the path Kivy still hangs on:

File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/app.py", line 828, in run runTouchApp() File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/base.py", line 487, in runTouchApp EventLoop.window.mainloop() File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/core/window/window_sdl2.py", line 619, in mainloop self._mainloop() File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/core/window/window_sdl2.py", line 362, in _mainloop EventLoop.idle() File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/base.py", line 327, in idle Clock.tick() File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/clock.py", line 493, in tick usleep(1000000 * (sleeptime - sleep_undershoot)) File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/clock.py", line 285, in usleep _libc_usleep(int(microseconds))

I will check later today if everything works on ubuntu 14.04.
[edit: Just checked, On Ubuntu everything works fine, when using 1.9.1]

@dessant
Copy link
Contributor

dessant commented Apr 15, 2016

Here is a cross-platform solution: https://pypi.python.org/pypi/monotonic.

@KeyWeeUsr
Copy link
Contributor

@dessant Wouldn't it be better to include monotonic into kivy? Roboto font has Apache 2.0 license too, so licensing probably shouldn't be a problem. If the speed is the factor, maybe including Monoclock might be the answer(as it's MIT), but that needs a work done for windows and maybe iOS?

@dessant
Copy link
Contributor

dessant commented Aug 27, 2016

I'd ask @matham which path seems best.

@matham matham removed this from the 2.0.0 milestone Oct 28, 2020
@Julian-O
Copy link
Contributor

I note that monotonic is built into Python >3.3, so we can just use that now.

@Julian-O Julian-O added Component: core-app app, clock, config, inspector, logger, resources, modules, clock, base.py Type: Bug A bug or something not working as intended labels Nov 12, 2023
@misl6
Copy link
Member

misl6 commented Nov 12, 2023

Some additional info for the future:

In Python 3.11, time.sleep:

Changed in version 3.11: On Unix, the clock_nanosleep() and nanosleep() functions are now used if available. On Windows, a waitable timer is now used.

Basically, now Python almost follows our approach, but by using a monotonic clock.

Idea 💡: Better to use time.sleep() instead of our custom solution for 3.11 and onwards?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: core-app app, clock, config, inspector, logger, resources, modules, clock, base.py Priority: High Should be fixed ASAP Type: Bug A bug or something not working as intended
Projects
None yet
Development

No branches or pull requests

6 participants