python / python/cpython

Reported resolution of `time.process_time` and `time.thread_time` is wrong on Windows

未关闭
#135,304 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

extension-modules OS-windows type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:
>>> import time
>>> time.get_clock_info("process_time")
namespace(implementation='GetProcessTimes()', monotonic=True, adjustable=False, resolution=1e-07)
>>> time.get_clock_info("thread_time")
namespace(implementation='GetThreadTimes()', monotonic=True, adjustable=False, resolution=1e-07)

The reported resolution=1e-07 is way off. According to @eryksun in https://github.com/python/cpython/issues/82040#issuecomment-1093831784

Don't read too much into the clock info here:
Process times [1] are stored as a 64-bit integer in units of 100 ns (1e-7). But the kernel schedules threads based on a timer that ticks every 15.625 ms by default. It can be lowered to about 0.5 ms, but this degrades battery life.

This has also caused problems in test_int.test_denial_of_service, see https://github.com/python/cpython/issues/114911#issuecomment-2567094984.

I suggest to report 15.625 ms, since this is the upper limit.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs
  • gh-135305

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先查看关联的 PR gh-135305,以及 Windows 上 time.get_clock_info("process_time") 和 time.get_clock_info("thread_time") 的行为。检查 test_int.test_denial_of_service 的相关影响;当报告的分辨率反映预期的 Windows 计时行为,并且受影响的测试通过时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
operating-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。