Python中C_PyTime_t的值是什么 [英] What is the value of C _PyTime_t in Python

查看:23
本文介绍了Python中C_PyTime_t的值是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

该值应为 9223372036.854775,即计算中 64 位有符号整数的最大值".请参阅这篇维基百科文章.

<块引用>

PEP 564:

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.

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中C_PyTime_t的值是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆