What is the value of C _PyTime_t in Python

Viewed 2767

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 _PyTime_t". What is the largest time length I can sleep?

2 Answers

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.

Related