selfcaffeinate
Description
Python module to prevent macOS system sleep using the caffeinate(1) command
Introduction to caffeinate(1)
macOS users can prevent system sleep using the system command caffeinate like so:
$ caffeinate sh -c "echo sleeping; sleep 60; echo done"
sleeping
done
$
Or hold a power management assertion on an existing process:
$ pgrep long-running-process
555
$ caffeinate -w 555 && echo "done"
done
This module allows caffeinate to be used programmatically from Python code to prevent system sleep, without having to run the command externally.
Example usage
def main():
print("Self caffeinating")
SLEEP_PERIOD = 60
sc = SelfCaffeinate()
for i in range(0, 60):
print("Sleeping {}".format(SLEEP_PERIOD))
time.sleep(SLEEP_PERIOD)
Or use the with pattern:
def main():
print("Self caffeinating")
SLEEP_PERIOD = 60
with SelfCaffeinate():
for i in range(0, 60):
print("Sleeping {}".format(SLEEP_PERIOD))
time.sleep(SLEEP_PERIOD)
The default path to macOS's caffeinate should work, but if you have an alternate path, you can specify that:
def main():
print("Self caffeinating")
SLEEP_PERIOD = 60
sc = SelfCaffeinate(caffeinate_path="/path/to/my/weird/caffeinate")
for i in range(0, 60):
print("Sleeping {}".format(SLEEP_PERIOD))
time.sleep(SLEEP_PERIOD)
Metadata
Release files for selfcaffeinate 0.1.0
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 |
|---|---|---|---|---|
| selfcaffeinate-0.1.0.tar.gz | 3.3 kB | Without provenance | Details for selfcaffeinate-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| selfcaffeinate-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for selfcaffeinate-0.1.0-py3-none-any.whl |
Total release size: 7.5 kB
Release files / selfcaffeinate-0.1.0.tar.gz
| Download URL | selfcaffeinate-0.1.0.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be4a3df2ff9f766d9bed29e133c066bbcffbcba2383468836f2eb167889d11cd
|
|
BLAKE2b-256 checksum How to use checksums |
b6b3e61adb79e3c2ff353c84b20e602ddd0fcda10b4f21af0a26206221696cd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.6.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.6
|
Release files / selfcaffeinate-0.1.0-py3-none-any.whl
| Download URL | selfcaffeinate-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a10243591ff79b9280fd4d6d0362aed1ea5b0e22332b6a67fa7f63b430d4c23
|
|
BLAKE2b-256 checksum How to use checksums |
119e38d1628362a297b7841b46dd96a938817a2db57ac28b7a000d9e517c735c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.6.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.6
|
Security for selfcaffeinate 0.1.0
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.