gpt4 book ai didi

python - Python 中 C _PyTime_t 的值

转载 作者:太空宇宙 更新时间:2023-11-04 05:01:05 24 4
gpt4 key购买 nike

当在 Python 3 中长时间休眠(如运行 time.sleep(3**3**3))时,程序会返回一个 OverflowError,错误消息为“timestamp too large to转换为 C _PyTime_t”。我最多可以睡多长时间?

最佳答案

该值应为 9223372036.854775,即“是计算中 64 位有符号整数的最大值”。参见 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 ** 9
9223372036.854776
>>> time.sleep(9223372036.854775)
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyboardInterrupt
>>> time.sleep(9223372036.854776)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: timestamp too large to convert to C _PyTime_t
>>>

关于python - Python 中 C _PyTime_t 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45704243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com