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

time.time() can go backwards #1470

Closed
totaam opened this issue Mar 23, 2017 · 7 comments
Closed

time.time() can go backwards #1470

totaam opened this issue Mar 23, 2017 · 7 comments

Comments

@totaam
Copy link
Collaborator

totaam commented Mar 23, 2017

A number of places assume that this is never the case.
This can cause problems when ntp adjusts the time.

@totaam
Copy link
Collaborator Author

totaam commented Mar 23, 2017

Monotonic time is implemented in python 3.3 and later: time.monotonic and
CLOCK_MONOTONIC.

For python2, we can use ctypes: [http://stackoverflow.com/a/1205762/428751] but the problem here is performance:

import timeit
from time import time
from xpra.os_util import monotonic_time
timeit.timeit(monotonic_time, number=1000000)
1.3700509071350098
timeit.timeit(time, number=1000000)
0.04274415969848633

So using ctypes is 33 times slower than calling "time"!
And osx doesn't have a librt, win32 doesn't have support for monotonic clocks at all?

@totaam
Copy link
Collaborator Author

totaam commented Mar 23, 2017

  • r15365 converts almost all time.time() calls to a os_util wrapper named monotonic_time (defaults to still use time.time())
  • r15366 + r15367 converts it to using a cythonized version, which is just as fast and actually monotonic

For win32 we would need to call GetTickCount64 and translate that into a time value... from a starting reference point ourselves. This would allow us to cimport the function from all the cython modules, saving conversion to a python type and back.

This will do. Tested on both Linux and macosx.

@totaam totaam closed this as completed Mar 23, 2017
@totaam
Copy link
Collaborator Author

totaam commented Mar 23, 2017

r15368 (+r15369 fixup) does implement it for win32 so we can cimport the function from all the cython modules.

@totaam
Copy link
Collaborator Author

totaam commented Mar 24, 2017

r15376 fixes the RPM packaging.

@totaam
Copy link
Collaborator Author

totaam commented Jul 21, 2017

Similar fix applied to the Javascript code in r16441.

@totaam
Copy link
Collaborator Author

totaam commented Nov 22, 2018

Caused a bug: #2038

@totaam
Copy link
Collaborator Author

totaam commented Sep 26, 2023

Switched back to the standard library in 1f270b9

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

No branches or pull requests

1 participant