栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在python中获得单调的持续时间?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在python中获得单调的持续时间?

该函数非常简单,您可以使用ctypes来访问它:

#!/usr/bin/env python__all__ = ["monotonic_time"]import ctypes, osCLOCK_MONOTONIC_RAW = 4 # see <linux/time.h>class timespec(ctypes.Structure):    _fields_ = [        ('tv_sec', ctypes.c_long),        ('tv_nsec', ctypes.c_long)    ]librt = ctypes.CDLL('librt.so.1', use_errno=True)clock_gettime = librt.clock_gettimeclock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]def monotonic_time():    t = timespec()    if clock_gettime(CLOCK_MONOTONIC_RAW , ctypes.pointer(t)) != 0:        errno_ = ctypes.get_errno()        raise OSError(errno_, os.strerror(errno_))    return t.tv_sec + t.tv_nsec * 1e-9if __name__ == "__main__":    print monotonic_time()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/408652.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号