Skip to main content

sleep_until

This module provides a function sleep_until(deadline_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. Limited testing has shown that sleep_until should still work in a predictable fashion (either returning immediately if the system clock is adjusted back, or sleeping until the specified wall-clock time if the system clock is adjusted forwards), however, this behavior can currently not be guaranteed by this module, so be sure to test the behavior on your system if you expect to be making adjustments to the system clock while sleep_until is running (including via a background NTP service).

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

Here is how one might implement a loop that executes at a specific 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 wake-up 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())

Metadata

Release files for sleep-until 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sleep-until 1.1
File Size Uploaded
sleep_until-1.1.tar.gz 11.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for sleep-until 1.1
File
sleep_until-1.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
sleep_until-1.1-cp314-cp314-win32.whl CPython 3.14 CPython 3.14 Windows x86-32 Details
sleep_until-1.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
sleep_until-1.1-cp313-cp313-win32.whl CPython 3.13 CPython 3.13 Windows x86-32 Details
sleep_until-1.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
sleep_until-1.1-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details
sleep_until-1.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
sleep_until-1.1-cp311-cp311-win32.whl CPython 3.11 CPython 3.11 Windows x86-32 Details
sleep_until-1.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
sleep_until-1.1-cp310-cp310-win32.whl CPython 3.10 CPython 3.10 Windows x86-32 Details

Total release size: 106.4 kB

Release files / sleep_until-1.1.tar.gz

Download URL sleep_until-1.1.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
aeb79fe10e4ecd0adcd8f97d9d2059710b16478e3668d0979d7dd29f8e4e4145
BLAKE2b-256 checksum
How to use checksums
75a2e8283749a630fec64128bf5ccd0b108fcaca2c0aba3f10362803d6e265b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp314-cp314-win_amd64.whl

Download URL sleep_until-1.1-cp314-cp314-win_amd64.whl
Size 9.7 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
96f6d5300b7a2b9cc1ae72631a3313d3b8af7c6dda3d81fa810266353f10e6bf
BLAKE2b-256 checksum
How to use checksums
d76cda16abf4e35b1f6e52965bb9e4c4fa3ac176d5d4ce5003067b4e20393e08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp314-cp314-win32.whl

Download URL sleep_until-1.1-cp314-cp314-win32.whl
Size 9.5 kB
Tags CPython 3.14 Windows x86-32
SHA-256 checksum
How to use checksums
a58159b41a73e6ab1e35824c8eafb4db32f44a907351b491580c4239d478fa45
BLAKE2b-256 checksum
How to use checksums
f31669d946e2c6caa77b19a437ae2443b344b724eb8beed0ebf57df76b370ac1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp313-cp313-win_amd64.whl

Download URL sleep_until-1.1-cp313-cp313-win_amd64.whl
Size 9.6 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
a89bbf8ac29b58ff3960eb013f9e700646e8d2404754894fe9c905dc9e0fafa1
BLAKE2b-256 checksum
How to use checksums
48fd600e694674fb288ba93d3d059aed69b2f826678be66646284a2c01b8bf5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp313-cp313-win32.whl

Download URL sleep_until-1.1-cp313-cp313-win32.whl
Size 9.3 kB
Tags CPython 3.13 Windows x86-32
SHA-256 checksum
How to use checksums
2ee68a408cf7982fa3f77eb41059484783ba99956a50ac788ba181a348b84bf3
BLAKE2b-256 checksum
How to use checksums
65c745f478f4400bc173446a6de4e0552cb0c44d6354068c557f17bde9b8495a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp312-cp312-win_amd64.whl

Download URL sleep_until-1.1-cp312-cp312-win_amd64.whl
Size 9.6 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
7b0dc58e72831c949b944c4f884306b03b3bc5fabfde1f1b13f7da3373b009f4
BLAKE2b-256 checksum
How to use checksums
3f0ac2e83e9a3c15cbeb8ef9502c223b22f60cbbeb662a2b30c099158cff9fee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp312-cp312-win32.whl

Download URL sleep_until-1.1-cp312-cp312-win32.whl
Size 9.3 kB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
263b7dca1821300633fb2d840250bede94365c637e581beb2eb8fadb1a1b0271
BLAKE2b-256 checksum
How to use checksums
8207bcac5d1900ebc90c1a78b11069e012f71ff35ea0a483a743f08045b03c44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp311-cp311-win_amd64.whl

Download URL sleep_until-1.1-cp311-cp311-win_amd64.whl
Size 9.6 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
1d2cc9d5cd2ae907a532c36bd2e06eb41e4f6479d5ae8b1c8dd2baaf0d83b73a
BLAKE2b-256 checksum
How to use checksums
3bc6db0f7e78a87cc70744bc71a4913c24930d7b10bd8b0e4fb160f28fe856a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp311-cp311-win32.whl

Download URL sleep_until-1.1-cp311-cp311-win32.whl
Size 9.3 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
7a63c39538892c1c5ba3a14625214ecc996c0d3691ebe1f17cb6b1f0706e122f
BLAKE2b-256 checksum
How to use checksums
91191a9fa8f8b6eac46bf828ab57c13574f4d129003b4b605f2087531371526e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp310-cp310-win_amd64.whl

Download URL sleep_until-1.1-cp310-cp310-win_amd64.whl
Size 9.6 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
823e74cd1ec7bfc64a6fda49ff48a423fab07f97f03cc38a07061a9f108fcbf9
BLAKE2b-256 checksum
How to use checksums
e83bc820ce83243eabfe93a20923424623096890780d2b5f165e3fa788b3c635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / sleep_until-1.1-cp310-cp310-win32.whl

Download URL sleep_until-1.1-cp310-cp310-win32.whl
Size 9.3 kB
Tags CPython 3.10 Windows x86-32
SHA-256 checksum
How to use checksums
492361800581071b8e459ef4c113842f1576ee37f0bc72fca7367cc1de226482
BLAKE2b-256 checksum
How to use checksums
3eb98939706bb824ad223a75d49450b7a312ac0b661d5db9b0b48c2613832b62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.1 This release

11 release files

1.0

15 release files

0.9

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page