Simple wakelock / keep-awake / stay-awake
Project description
⏰😴 wakepy
Simple cross-platform wakelock written in Python. Keeps your computer from going to sleep.
Table of Contents
Requirements
Wakepy currently supports
- Windows
- Linux (with
systemd
) - macOS
Feel free to submit pull request(s) for other platforms.
Installing
pip install wakepy
Usage
Start from command line
python -m wakepy
Starts the program. While running, computer will not go to sleep. If battery is running out, your OS might force laptop to sleep.
CLI
python -m wakepy [-h] [-s]
optional arguments:
-h, --help show this help message and exit
-s, --keep-screen-awake Keep also the screen awake. On Linux, this flag is set on and cannot be disabled.
Usage within a python script
Option 1: set_keepawake
and unset_keepawake
functions
from wakepy import set_keepawake, unset_keepawake
set_keepawake(keep_screen_awake=False)
# do stuff that takes long time
unset_keepawake()
Option 2: keepawake
context manager
new in version 0.4.0
from wakepy import keepawake
with keepawake(keep_screen_awake=False):
... # do stuff that takes long time
Parameters
keep_screen_awake
can be used to keep also the screen awake. The default isFalse
. On Linux, this is set toTrue
and cannot be changed.
Details
Windows
The program simply calls the SetThreadExecutionState with the ES_SYSTEM_REQUIRED
flag, when setting the keepawake, and removes flag when unsetting. The flag cannot prevent sleeping if
- User presses power button
- User selects Sleep from the Start menu.
Linux
The program uses the systemctl mask
command to prevent all forms of sleep or hybernation when setting the keepawake, and unmasks the functions when unsetting keepawake. This command will remain active until keepawake is removed. The flag cannot prevent sleeping from user interaction. This action does require sudo privileges.
Darwin (macOS)
The program calls the caffeinate
command when setting keepawake, and sends a break key-command when unsetting. The flag does not prevent the user from manually sleeping the system or terminating the caffeinate process.
⚖️ Pros and Cons
👑💯 Advantages of wakepy
- wakepy has zero (python) dependencies
- wakepy is simple and it has a little amount of code. You can read the whole source code quickly
- It has permissive MIT licence
- It is multiplatform
- You can use it directly from command line, or within your python scripts
🔍❕ Disadvantages / pitfalls with wakepy
- Currently multiprocessing is not well supported; the first function calling
unset_keepawake
or releasing thekeepawake
context manager will allow the PC to sleep even if you have calledset_keepawake
multiple times. For these kind of cases, perhaps an implementation making mouse movement or pressing keyboard keys would work better.
Changelog
- See CHANGELOG.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file wakepy-0.4.1.tar.gz
.
File metadata
- Download URL: wakepy-0.4.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a13d4c01c662f4987abe777f9b74c34a5f4db482bc3afa515747504d526aa82 |
|
MD5 | 5eb45ce5104a79c203e73ad4d4786afb |
|
BLAKE2b-256 | 2c83e39e4e57f26c02bf878cc1f6cd980bdb408cdd953101f9f32f4517b8448e |