问题描述
在 Python 3 中长时间睡眠时(如运行 time.sleep(3**3**3)
),程序返回一个 OverflowError,错误消息为timestamp too large to转换为 C _PyTime_t".我最多可以睡多久?
该值应为 9223372036.854775,即计算中 64 位有符号整数的最大值".请参阅这篇维基百科文章.
在 :
CPython 私有的pytime"C API 处理时间现在使用新的 _PyTime_t 类型:简单的 64 位有符号整数 (C int64_t)._PyTime_t 单元是一个实现细节,而不是 API 的一部分.当前单位为 1 纳秒.
>>>2 ** 63/10 ** 99223372036.854776>>>时间.sleep(9223372036.854775)^CTraceback(最近一次通话):文件<stdin>",第 1 行,在 <module> 中.键盘中断>>>时间.sleep(9223372036.854776)回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中.溢出错误:时间戳太大而无法转换为 C _PyTime_t>>>
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?
The value should be 9223372036.854775, which is "is the maximum value for a 64-bit signed integer in computing". See this Wikipedia article.
>>> 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中C_PyTime_t的值是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!