python等价于std::chrono::steady_clock::now();

2024-06-28 15:40:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图把C++代码转换成Python。我可以用什么python等价物来代替std::chrono::steady_clock::now();,它给出了linux上当前时间的精确计时,可以与其他时间点进行比较。在

void takeImages(steady_clock::time_point next_frame)
{

    steady_clock::time_point current_time = steady_clock::now();

    if (current_time >= next_frame) {
        // do something if time right now is at or after next_frame
}

Tags: 代码iftimelinux时间currentframenow
1条回答
网友
1楼 · 发布于 2024-06-28 15:40:49

这相当于Python中的time.monotonic()。见time — Time access and conversions

Return the value (in fractional seconds) of a monotonic clock, i.e. a clock that cannot go backwards. The clock is not affected by system clock updates. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.

遗憾的是C++在这里使用了不寻常的命名法。“单调”是其他标准和语言(C11、Posix、Python等)使用的术语。在

相关问题 更多 >