Skip to main content

Sleep until a specific time

Project description

sleep_until

This module provides a function sleep_until(seconds), which is like time.sleep(), but it sleeps until the specified time of the system clock as returned by time.time(). This can be used, for example, to schedule events at a specific timestamp obtained from datetime.datetime.timestamp().

See the notes in time.sleep() on the behavior when interrupted and on accuracy. Additionally, because this function uses the system clock as a reference (CLOCK_REALTIME on Unix), this means the reference clock is adjustable and may jump backwards.

  • On Windows, SetWaitableTimerEx is used, in combination with CREATE_WAITABLE_TIMER_HIGH_RESOLUTION if available. Precompiled "wheels" for CPython are available on PyPI.
  • On POSIX systems, clock_nanosleep(2) is used, so this must be available, along with the appropriate tools to compile the module.
  • On Mac OS X, at the time of writing, clock_nanosleep is not available, so the module currently does not build there.

The test.py script can be used to test the functionality of the module.

Here is how one might implement a loop that executes at a fixed interval:

from time import time
from sleep_until import sleep_until

interval_s = 1

# using "int" here to start on a full second
next_s = int(time()) + interval_s
while True:
    # calculate the next wakeup time and sleep until then
    now_s = time()
    # if the user's code takes longer than the interval, skip intervals
    while next_s < now_s: next_s += interval_s
    sleep_until(next_s)

    # run any user-specified code here
    print(time())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sleep_until-1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distributions

sleep_until-1.0-cp312-cp312-win_amd64.whl (8.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

sleep_until-1.0-cp312-cp312-win32.whl (8.4 kB view details)

Uploaded CPython 3.12 Windows x86

sleep_until-1.0-cp311-cp311-win_amd64.whl (8.6 kB view details)

Uploaded CPython 3.11 Windows x86-64

sleep_until-1.0-cp311-cp311-win32.whl (8.3 kB view details)

Uploaded CPython 3.11 Windows x86

sleep_until-1.0-cp310-cp310-win_amd64.whl (8.6 kB view details)

Uploaded CPython 3.10 Windows x86-64

sleep_until-1.0-cp310-cp310-win32.whl (8.3 kB view details)

Uploaded CPython 3.10 Windows x86

sleep_until-1.0-cp39-cp39-win_amd64.whl (8.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

sleep_until-1.0-cp39-cp39-win32.whl (8.3 kB view details)

Uploaded CPython 3.9 Windows x86

sleep_until-1.0-cp38-cp38-win_amd64.whl (8.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

sleep_until-1.0-cp38-cp38-win32.whl (8.3 kB view details)

Uploaded CPython 3.8 Windows x86

sleep_until-1.0-cp37-cp37m-win_amd64.whl (8.6 kB view details)

Uploaded CPython 3.7m Windows x86-64

sleep_until-1.0-cp37-cp37m-win32.whl (8.3 kB view details)

Uploaded CPython 3.7m Windows x86

sleep_until-1.0-cp36-cp36m-win_amd64.whl (7.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

sleep_until-1.0-cp36-cp36m-win32.whl (7.4 kB view details)

Uploaded CPython 3.6m Windows x86

File details

Details for the file sleep_until-1.0.tar.gz.

File metadata

  • Download URL: sleep_until-1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0.tar.gz
Algorithm Hash digest
SHA256 7267da857ff7118f7315172b0fba3aba86ee32b6f51d5c4197e657e47a953c6d
MD5 d2f925784b151e65bd4548dd9dbe7e0a
BLAKE2b-256 0a32e2a80252acf4f971aedeca29b312d2aea1d26d1e2695c63d8faaf2a050d5

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for sleep_until-1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f1a2018d5d963f5ec4c3bc43497d597667fc5da55279fc305b51a8807aa01c35
MD5 84199c2ff1bcfe47fca5b9339fe25852
BLAKE2b-256 ec580b9cca9a51dc30bd4353aab280c3ebc09b2ade744c282f486c9b076fbc89

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp312-cp312-win32.whl.

File metadata

  • Download URL: sleep_until-1.0-cp312-cp312-win32.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for sleep_until-1.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 da8747a2456ad1b018af1ee8c4ce3fd6ecc923343d721c846e8014e01fe2108c
MD5 aa524e16c56e3f209c365f60d91195de
BLAKE2b-256 5d0ce2187a99692321b48b690a64faab5f37da85f250da8dcc8da134d542c53e

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for sleep_until-1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ac289b9a2355978fe7193ca8b6c3f1a16f55586230c2ac9e6181707369c971db
MD5 798486c810ec6add6d101189a9493cfe
BLAKE2b-256 c59f181bc10b7bc91897fb0b34e43263651a764550eee9f7a023bfae6ee629d5

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp311-cp311-win32.whl.

File metadata

  • Download URL: sleep_until-1.0-cp311-cp311-win32.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 00e37380584132ee3241d1ab42290e9d15d8b8bac925ff9b907d69f24e54300a
MD5 528e15093d3059a7011a5dfb89eb22fe
BLAKE2b-256 d20827d8ece223e4cfbaf441c706fc699984f37718ff8419483e778f85882b25

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for sleep_until-1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1f35ff8aae77b33519f0556aff8504b52a8faeb1d2cc1f69d9a7be778eaaaf6b
MD5 1c3e1b05a07e9b0f0db927002649fa6a
BLAKE2b-256 0b30903c9d057a8a8f303ce18aa6d0930fa8a73ce3f8c1b7618b301648cc9788

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp310-cp310-win32.whl.

File metadata

  • Download URL: sleep_until-1.0-cp310-cp310-win32.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 2a70a26d8b59a216f13054362442e12b149025f841c467a6d4e3d90e8059a03a
MD5 d67a5329ee1736cdf3aa539d2dbee045
BLAKE2b-256 337317e3052f32b0dbb3f9a48e10a253a2b015c59434941bee400c415016b6c6

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: sleep_until-1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5693c3b8d88b5f648eff2bdb7a68f91fbdd8db170c5359080fda20732be0b0ad
MD5 1c4f0792b9e44e62d62319612709756c
BLAKE2b-256 6a935154a2d7d78a06c868d78f58ad89a703c75e51cacbba4d9bef1693f4a593

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp39-cp39-win32.whl.

File metadata

  • Download URL: sleep_until-1.0-cp39-cp39-win32.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 269d5d78e24a160dbca84f69a710a295e5bc1b288d61c31015ba2f614ae7a764
MD5 797fd8959c37c1993ec6124f88664785
BLAKE2b-256 a686518f41ca31d8a1807f109b46860e18b81beee093d9a8ceefc9edc76089f1

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: sleep_until-1.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 855952fd884cf5ab7ef1df263ca20cea0e623b881725e694ed9411d677a8b951
MD5 bfe2902d86f58ffbfde32704b039d28e
BLAKE2b-256 69488a3afe4f087cb21c3186c2c2ac360321a1fc8cff5df58998bc400f34b112

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp38-cp38-win32.whl.

File metadata

  • Download URL: sleep_until-1.0-cp38-cp38-win32.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 e937f24209872ae6ab57bbe3ec59252ddc01487f796e8cc861e8c28a41cde562
MD5 5378e7c126e0bb06dfaa46187cc68c16
BLAKE2b-256 f650bd76ad124f2206b121f2ced066027af119f5ed533e4deeabeeb6a98e6933

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for sleep_until-1.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 8d947cf437af768a04ad0b32a658f4d9d089b61a6ef37155f47ea684abcb427b
MD5 9c3b1b142d03bb9c5dac06c1bd1c0e2f
BLAKE2b-256 672d4931be5d946ff9ee58dc065846dd1af3e0be98a7010b193a65abca841a8c

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp37-cp37m-win32.whl.

File metadata

  • Download URL: sleep_until-1.0-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 c1158ac39fddfa05d4e2168582e88715cdf38cc0ec755120ab7b6c6e7a0be31a
MD5 972574897a14375bdb2b93e1012a9740
BLAKE2b-256 5ff364fe4e5a11fcb093922082d348a3d05f3ee4108ee878f35f90a2419ac2bd

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for sleep_until-1.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 196ed0f9feeae28883d6fe0d66137f72b66e953036c9f3fe540937f8147acf3f
MD5 02d99b25b8409d55438d9a4c3e76b541
BLAKE2b-256 fe0d466513f6e12676911289c322a20ac7d740825e86c61cf5258a3c89495d2f

See more details on using hashes here.

File details

Details for the file sleep_until-1.0-cp36-cp36m-win32.whl.

File metadata

  • Download URL: sleep_until-1.0-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for sleep_until-1.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 225fb5cb3308b072d8aad5b8ab3ac535a67b3379aca2a4a5f12646c7490e8835
MD5 8b7def4f1ff702cc4f6fa082029457fa
BLAKE2b-256 8d45e5cbbd25bdfda88eead29414fd7108279cb0a58f6acbf4425620ea3749da

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page