Commit Graph

27 Commits

Author SHA1 Message Date
Victor Stinner a47b881d86 Issue #22117: time.time() now uses the new _PyTime_t API
* Add _PyTime_GetSystemClockWithInfo()
2015-03-27 18:16:17 +01:00
Victor Stinner 4bfb460d88 Issue #22117: time.monotonic() now uses the new _PyTime_t API
* Add _PyTime_FromNanoseconds()
* Add _PyTime_AsSecondsDouble()
* Add unit tests for _PyTime_AsSecondsDouble()
2015-03-27 22:27:24 +01:00
Victor Stinner 992c43fec9 Issue #22117: Fix rounding in _PyTime_FromSecondsObject()
* Rename _PyTime_FromObject() to _PyTime_FromSecondsObject()
* Add _PyTime_AsNanosecondsObject() and _testcapi.pytime_fromsecondsobject()
* Add unit tests
2015-03-27 17:12:45 +01:00
Victor Stinner eb352295fd Issue #23451, #22117: Python 3.5 now requires Windows Vista or newer, so
GetTickCount64() is now always available.
2015-03-27 14:12:08 +01:00
Victor Stinner cb29f0177c Issue #22117: Add a new Python timestamp format _PyTime_t to pytime.h
In practice, _PyTime_t is a number of nanoseconds. Its C type is a 64-bit
signed number. It's integer value is in the range [-2^63; 2^63-1]. In seconds,
the range is around [-292 years; +292 years]. In term of Epoch timestamp
(1970-01-01), it can store a date between 1677-09-21 and 2262-04-11.

The API has a resolution of 1 nanosecond and use integer number. With a
resolution on 1 nanosecond, 64-bit IEEE 754 floating point numbers loose
precision after 194 days. It's not the case with this API. The drawback is
overflow for values outside [-2^63; 2^63-1], but these values are unlikely for
most Python modules, except of the datetime module.

New functions:

- _PyTime_GetMonotonicClock()
- _PyTime_FromObject()
- _PyTime_AsMilliseconds()
- _PyTime_AsTimeval()

This change uses these new functions in time.sleep() to avoid rounding issues.

The new API will be extended step by step, and the old API will be removed step
by step. Currently, some code is duplicated just to be able to move
incrementally, instead of pushing a large change at once.
2015-03-27 13:31:18 +01:00
Victor Stinner 580ef1345a Cleanup pytime.c: add XXX_TO_YYY constants (ex: SEC_TO_US) 2015-03-20 01:55:04 +01:00
Victor Stinner 9a8089b32a Issue #23646: Enhance precision of time.sleep() and socket timeout when
interrupted by a signal

Add a new _PyTime_AddDouble() function and remove _PyTime_ADD_SECONDS() macro.
The _PyTime_ADD_SECONDS only supported an integer number of seconds, the
_PyTime_AddDouble() has subsecond resolution.
2015-03-20 01:42:20 +01:00
Steve Dower 3e96f324dc Issue #23451: Update pyconfig.h for Windows to require Vista headers and remove unnecessary version checks. 2015-03-02 08:01:10 -08:00
Victor Stinner 5789cfbb56 Issue #22043: Fix pymonotonic(), use tv_usec=-1 as a marker to skip
the monotonic test
2014-09-03 09:43:48 +02:00
Victor Stinner ae58649721 Issue #22043: time.monotonic() is now always available
threading.Lock.acquire(), threading.RLock.acquire() and socket operations now
use a monotonic clock, instead of the system clock, when a timeout is used.
2014-09-02 23:18:25 +02:00
Victor Stinner 9bb758cee7 Issue #22043: Fix _PyTime_gettimeofday() if HAVE_GETTIMEOFDAY
Ensure also that the tv_usec field is consistent: in range [0; 999999].
2014-09-02 23:01:40 +02:00
Victor Stinner 0011124dc2 Issue #22043: _PyTime_Init() now checks if the system clock works.
Other changes:

* The whole _PyTime API is private (not defined if Py_LIMITED_API is set)
* _PyTime_gettimeofday_info() also returns -1 on error
* Simplify PyTime_gettimeofday(): only use clock_gettime(CLOCK_REALTIME) or
  gettimeofday() on UNIX. Don't fallback to ftime() or time() anymore.
2014-08-29 16:31:59 +02:00
Victor Stinner 7efb83393c Issue #22287: On UNIX, _PyTime_gettimeofday() now uses
clock_gettime(CLOCK_REALTIME) if available. As a side effect, Python now
depends on the librt library on Solaris and on Linux (only with glibc older
than 2.17).
2014-08-29 15:41:08 +02:00
Victor Stinner 3c1b379ebd Issue #20320: select.select() and select.kqueue.control() now round the timeout
aways from zero, instead of rounding towards zero.

It should make test_asyncio more reliable, especially test_timeout_rounding() test.
2014-02-17 00:02:43 +01:00
Victor Stinner 2b89fdf7eb PEP 418: Rename adjusted attribute to adjustable in time.get_clock_info() result
Fix also its value on Windows and Linux according to its documentation:
"adjustable" indicates if the clock *can be* adjusted, not if it is or was
adjusted.

In most cases, it is not possible to indicate if a clock is or was adjusted.
2012-06-12 22:46:37 +02:00
Larry Hastings 76ad59b7e8 Issue #14127: Add ns= parameter to utime, futimes, and lutimes.
Removed futimens as it is now redundant.
Changed shutil.copystat to use st_atime_ns and st_mtime_ns from os.stat
and ns= parameter to utime--it once again preserves exact metadata on Linux!
2012-05-03 00:30:07 -07:00
Benjamin Peterson 49a69e4d48 strip is_ prefixes on clock_info fields 2012-05-01 09:38:34 -04:00
Victor Stinner ec89539ccc Issue #14428, #14397: Implement the PEP 418
* Rename time.steady() to time.monotonic()
 * On Windows, time.monotonic() uses GetTickCount/GetTickCount64() instead of
   QueryPerformanceCounter()
 * time.monotonic() uses CLOCK_HIGHRES if available
 * Add time.get_clock_info(), time.perf_counter() and time.process_time()
   functions
2012-04-29 02:41:27 +02:00
Larry Hastings 6fe20b3aee Issue #14127: Add st_{cma}time_ns fields to os.stat() result object. 2012-04-19 15:07:49 -07:00
Victor Stinner bd273c1ec3 Issue #14180: Fix an invalid rounding when compiler optimization are enabled
Use volatile keyword to disable localy unsafe float optimizations.
2012-03-13 19:12:23 +01:00
Victor Stinner 3a31dd407a Issue #14180: Remove commented code 2012-03-13 13:50:34 +01:00
Victor Stinner 5d272cc6a2 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
time.ctime(), gmtime(), time.localtime(), datetime.date.fromtimestamp(),
datetime.datetime.fromtimestamp() and datetime.datetime.utcfromtimestamp() now
raises an OverflowError, instead of a ValueError, if the timestamp does not fit
in time_t.

datetime.datetime.fromtimestamp() and datetime.datetime.utcfromtimestamp() now
round microseconds towards zero instead of rounding to nearest with ties going
away from zero.
2012-03-13 13:35:55 +01:00
Victor Stinner 643cd68ea4 Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Add a private API to convert an int or float to a C timespec structure.
2012-03-02 22:54:03 +01:00
Victor Stinner 4195b5caea Backout f8409b3d6449: the PEP 410 is not accepted yet 2012-02-08 23:03:19 +01:00
Victor Stinner ccd5715a14 PEP 410 2012-02-08 14:31:50 +01:00
Victor Stinner 09225b73c1 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
to have a resolution of 100 ns instead of 1 ms (the clock accuracy is between
0.5 ms and 15 ms).
2012-02-07 23:41:01 +01:00
Alexander Belopolsky 6fc4ade2bb Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
exposed in Python.h.  This function is similar to POSIX
gettimeofday(struct timeval *tp), but available on platforms without
gettimeofday().
2010-08-05 17:34:27 +00:00