Skip to content Skip to sidebar Skip to footer

What Is The Value Of C _pytime_t In Python

When sleeping for a long time (like running time.sleep(3**3**3)) in Python 3, the program returns an OverflowError with the error message 'timestamp too large to convert to C _PyTi

Solution 1:

The value should be 9223372036.854775, which is "is the maximum value for a 64-bit signed integer in computing". See this Wikipedia article.

Mentioning of _PyTime_t in PEP 564:

The CPython private "pytime" C API handling time now uses a new _PyTime_t type: simple 64-bit signed integer (C int64_t). The _PyTime_t unit is an implementation detail and not part of the API. The unit is currently 1 nanosecond.

>>>2**63/10**99223372036.854776>>> time.sleep(9223372036.854775)
^CTraceback (most recent calllast):
  File "<stdin>", line 1, in<module>
KeyboardInterrupt
>>> time.sleep(9223372036.854776)
Traceback (most recent calllast):
  File "<stdin>", line 1, in<module>
OverflowError: timestamp too largetoconvertto C _PyTime_t
>>>

Solution 2:

I found the following from the documentation of the threading library:

threading.TIMEOUT_MAX

The maximum value allowed for the timeout parameter of blocking functions (Lock.acquire(), RLock.acquire(), Condition.wait(), etc.). Specifying a timeout greater than this value will raise an OverflowError.

New in version 3.2.

On my system, with python 3.8:

>>> import threading
>>> threading.TIMEOUT_MAX
9223372036.0

I don't see it clearly specified anywhere that threading.TIMEOUT_MAX is a maximum for the argument to time.sleep(), but it appears to be the right value (or "close", for some reason), constructed with the same constraints.

Post a Comment for "What Is The Value Of C _pytime_t In Python"