Metadata-Version: 2.1
Name: clock_time
Version: 1.0
Summary: Provide sleep(secs)/time_s() functions
Home-page: https://bitbucket.org/wjssz/clock_time
Author: Ma Lin
Author-email: malincns@163.com
License: The 3-Clause BSD License
Keywords: sleep
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.0
Description-Content-Type: text/x-rst
License-File: LICENSE

Introduction
------------

Provide ``sleep(secs)`` / ``time_s()`` functions. Fix overflow bugs in CPython implementation so far (v3.14.0a1).


``sleep(secs)``
---------------

Use ``clock_nanosleep()`` with ``CLOCK_MONOTONIC`` to sleep. So that the sleep is not affected by system date/time jumps.

On CPython 3.11+, `time.sleep() <https://docs.python.org/3/library/time.html#time.sleep>`_ function already use this method.


``time_s()``
------------

Return time as an integer number of seconds since the `epoch <https://docs.python.org/3/library/time.html#epoch>`_.


Usage
-----

Only provide source code distribution, user need to install the build toolchain. It can't be compiled on platforms without ``clock_nanosleep()``.

.. sourcecode:: python

    try:
        from clock_time import sleep, time_s
    except ImportError:
        from time import sleep, time_ns
        def time_s():
            return time_ns() // 1_000_000_000

    sleep(secs)
    t = time_s()
