python-snoozebot: A coordinated and interruptible time.sleep() replacement
This module implements a time.sleep() replacement, snoozebot.snooze(), which is more suitable for use in multithreaded apps:
- Threads can be woken up (optionally, with an exception) to facilitate prompt, clean shutdown.
- Snoozing can be cut short if file descriptor(s) becomes readable
- Snoozing threads can specify an interval of acceptable wakeup times, to facilitate grouping jobs together (thus hopefully playing nice with powersavings on modern/mobile CPUs).
Usage:
import snoozebot
from snoozebot import Snoozer, snooze, wake_all
# Interruptable sleep for 1 second
snooze(1.0)
# Sleep for anywhere between 1 minute and 1 hour
snooze(60, 3600)
# Sleep an hour, but wake up early for activity on sys.stdin
reason = snooze(3600, watch_fds=[sys.stdin.fileno()])
if reason[0] == snoozebot.WOKE_FD:
data = reason[1].read()
# Create a re-usable schedule which can be woken by other means
sn = Snoozer(60, 3600, watch_fds=[sys.stdin.fileno()]))
sn.snooze()
# Other thread wakes us up...
sn.reason(snoozebot.WOKE_CUSTOM, 'Good morning!').wake()
# Just wake all snoozers
wake_all()
# Wake all snoozers with a KeyboardInterrupt!
wake_all(KeyboardInterrupt, 'Time to die')
Dependencies
You will need:
- Python 2.7 or 3.x (author tested on 3.7)
Bugs
This code will fail if firewalls prevent localhost from speaking UDP with itself.
Copyright, license, credits
This code is: (C) Copyright 2020, Bjarni R. Einarsson bre@klaki.net
Snoozebot is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Snoozebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with snoozebot. If not, see https://www.gnu.org/licenses/.
Metadata
Release files for snoozebot 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| snoozebot-0.0.3.tar.gz | 8.3 kB | Without provenance | Details for snoozebot-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snoozebot-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for snoozebot-0.0.3-py3-none-any.whl |
Total release size: 17.8 kB
Release files / snoozebot-0.0.3.tar.gz
| Download URL | snoozebot-0.0.3.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52170dc9ede4e149054d7a8cbaff8b636a91e328e37fbe2962d49e3c257327c4
|
|
BLAKE2b-256 checksum How to use checksums |
268175551a3e7b60fc8f7cedd00f23906cd061a25e2f364f1cbfc57538250d06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5
|
Release files / snoozebot-0.0.3-py3-none-any.whl
| Download URL | snoozebot-0.0.3-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e597516d6519e5185adcc9ab32fa18644abe6e6734a55701e7ba5f70a0479d95
|
|
BLAKE2b-256 checksum How to use checksums |
d78aea49538a0ed775c1a21d3632a270a9203a26e527415759e2efd676f67562
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5
|
Security for snoozebot 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.