Prevent hibernation/sleep while executing
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
### Feature Idea
Ability to prevent operating system to go to sleep/hibernation while server is executing queued items.
Use case:
When a user queues a large number of items and then leaves the PC, then the user would like to see all items completed before the PC goes to sleep.
Optional:
* Ability to configure hibernation behaviour of server as one of:
* Never prevent
* Prevent while executing
* Prevent while server is running
### Existing Solutions
As a workaround, I wrote a custom node that overrides the ```PromptExecutor.execute()``` function. I don't think there is an equivalent OS feature for Linux (?).
Question: Is there a more proper way to hook into execute() instead of brutally overriding the method?
```python
# __init__.py
import ctypes
import sys
from execution import PromptExecutor
class HibernationHandler:
def prevent_hibernation():
ES_CONTINUOUS = 0x80000000
ES_SYSTEM_REQUIRED = 0x00000001
ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)
def allow_hibernation():
ES_CONTINUOUS = 0x80000000
ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)
def wrapped_execute(self, prompt, prompt_id, extra_data={}, execute_outputs=[]):
HibernationHandler.prevent_hibernation()
try:
HibernationHandler.original_execute(self, prompt, prompt_id, extra_data, execute_outputs)
finally:
HibernationHandler.allow_hibernation()
def attach():
HibernationHandler.original_execute = PromptExecutor.execute
PromptExecutor.execute = HibernationHandler.wrapped_execute
if sys.platform == 'win32':
HibernationHandler.attach()
```
### Other
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.