TIL: wakepy
Leave your computer on forever
Sometimes in my job, I have tasks that need to run for an hour or two, like filling a local database with some data provided from a staging environment. I can only run this particular task in non-business hours. So basically between 12 p.m. and 2 p.m. or after 6 p.m. Naturally, I don’t want to stay on my computer to wait for the task to finish before leaving.
This is where wakepy is useful. It lets me keep my work computer on while I do other things.
Installation
You can install it with your favorite package manager, but you will probably want to install it globally with a tool like pipx or uv.
The minimum Python version supported at the moment of writing is 3.7.
$ pip install wakepy
# or with pipx
$ pipx install wakepy
# or with uv
$ uv tool install wakepyUsage
The usage is dead simple; you just need to run the following command:
$ wakepyBy default, it will keep the system from sleeping and prevent the screen lock. It is equivalent to wakepy -p.
If the screen lock is not an issue, you can run wakepy in the running mode.
$ wakepy -rThere is also a programmatic usage. But this time, you should install the package as a dependency of a project, not as a tool.
$ pip install wakepy
# or with uv
$ uv add wakepyFor example, if you need to run some code that takes a long time, like training a model, you can do this:
from wakepy import keep
@keep.running
def long_running_task():
process_large_dataset()
@keep.presenting
def slideshow():
display_presentation()There is also a decorator syntax.
from wakepy import keep
with keep.running():
# Do something that takes a long time
with keep.presenting():
# Do something that takes a long timeThis is all for this article, hope you enjoy reading it. Take care of yourself and see you soon. 😁
