Python resolution of datetime.now()

柔情痞子 提交于 2019-11-29 15:15:45

This may be a limitation of time.sleep on your system, rather than datetime.now()... or possibly both. What OS and what version and distribution of Python are you running on?

Your system may not offer the "subsecond precision" mentioned in the time.sleep docs:

sleep(...)
    sleep(seconds)

    Delay execution for a given number of seconds.  The argument may be
    a floating point number for subsecond precision.

On Linux 3.x on amd64 with CPython 2.7, I get something pretty close to the 0.0001 time steps that you intended:

2015-07-10 19:58:24.353711
2015-07-10 19:58:24.353879
2015-07-10 19:58:24.354052
2015-07-10 19:58:24.354227
2015-07-10 19:58:24.354401
2015-07-10 19:58:24.354577
2015-07-10 19:58:24.354757
2015-07-10 19:58:24.354938
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!