Download code/scripts/keep_task_awake.py from CollinMa/nextgpt-chapter6-report: direct link, hf CLI and curl.
- Browser
- Download file 918 Bytes
-
https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/keep_task_awake.py
- Command line
-
hf download hf://spaces/CollinMa/nextgpt-chapter6-report/code/scripts/keep_task_awake.py
-
curl -L -o keep_task_awake.py https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/keep_task_awake.py
918 Bytes
| """Temporarily prevent automatic system sleep while this pipeline process lives. | |
| No power plan is modified; manual sleep/shutdown still takes priority. | |
| """ | |
| import ctypes | |
| import json | |
| import time | |
| from pathlib import Path | |
| import psutil | |
| ROOT=Path(__file__).resolve().parents[1] | |
| if __name__=='__main__': | |
| state=json.loads((ROOT/'logs/pipeline-status.json').read_text(encoding='utf-8')) | |
| process=psutil.Process(state['pid']) | |
| expected=process.create_time() | |
| if 'local_pipeline.py' not in ' '.join(process.cmdline()): | |
| raise SystemExit('Pipeline identity mismatch') | |
| continuous=0x80000000 | |
| try: | |
| ctypes.windll.kernel32.SetThreadExecutionState(continuous|0x00000001) | |
| while process.is_running() and process.create_time()==expected: | |
| time.sleep(15) | |
| except psutil.NoSuchProcess: | |
| pass | |
| finally: | |
| ctypes.windll.kernel32.SetThreadExecutionState(continuous) | |