Comments (4)
Amazing timing. I actually was looking for the same thing in this library today. I think this would make my code that is consuming this library more readable. It seems to fit the general motivations for context managers outlined in PEP 343.
I made a PR if you are open to adding this. I did not address the multi-thread/process case you mentioned.
from wakepy.
I was thinking this a bit when I did the initial version. I think having a context manager version could make sense. Although, the set_keepawake()
and unset_keepawake()
are probably also needed:
- Function approach (
set_keepawake()
andunset_keepawake()
) is easy to understand even for beginners. - Function approach makes it possible to set the keepawake on one thread/process, and unset in some other thread/process.
The context manager approach has the positive of being a bit less verbose especially if there is some error handling. Do you see other benefits? It could be implemented as
with keepawake(**params):
# do stuff
and it could use the set_keepawake()
and unset_keepawake()
under the hood.
That being said, one day it might be interesting to have multiprocessing-supporting approach that uses a counter under the hood; for each set_keepawake()
call there should be unset_keepawake()
and for example if one calls set_keepawake()
three times, the unset_keepawake()
should be called three times before it would actually bet unset. In current implementation, if there were three long running processes (2hrs, 30hrs and 30hrs), and all of them would be using unset_keepawake()
, PC would sleep soon after 2hrs.
from wakepy.
Thanks for the PR! The context manager is now part of 0.4.0 and available in PyPI.
from wakepy.
Awesome, thanks!
from wakepy.
Related Issues (20)
- inv test failing on Windows
- Code coverage not shown on windows (inv test)
- Importing wakeypy nukes logging config HOT 3
- GitHub Releases are not shown (except to repo owner) HOT 3
- There's still one place calling the log methods of the logging module directly (logging.info())
- Publish also to conda-forge?
- Rename the CLI flags: Have same naming convention everywhere. --keep-presenting and -r
- Android support
- Add support for BSD systems HOT 3
- Keep a remote server awake after closing SSH connection? HOT 2
- Improve Supported Platforms table
- Wakepy on browser (Pyodide, PyPy.js, Brython, Transcrypt, Skulpt)
- Add support for cygwin
- Add support for ChromeOS
- Add to docs: "Prior to Windows 11 power requests were held an additional 2 minutes after they were dropped by the application. "
- Update migration guide: Add on_fail action example
- Docs: Tell that (most of?) the wakepy Methods will keep the idle/sleep timer at zero for the duration of the context manager
- Conditionally using wakepy modes
- on_success / on_activation hook? (similar to on_fail)
- Include `on_fail="warn"` in the examples of the README / docs?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wakepy.