intellif-aihub 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of intellif-aihub might be problematic. Click here for more details.
- intellif_aihub-0.1.0/PKG-INFO +6 -0
- intellif_aihub-0.1.0/aihub/__init__.py +3 -0
- intellif_aihub-0.1.0/aihub/stop.py +36 -0
- intellif_aihub-0.1.0/intellif_aihub.egg-info/PKG-INFO +6 -0
- intellif_aihub-0.1.0/intellif_aihub.egg-info/SOURCES.txt +7 -0
- intellif_aihub-0.1.0/intellif_aihub.egg-info/dependency_links.txt +1 -0
- intellif_aihub-0.1.0/intellif_aihub.egg-info/top_level.txt +1 -0
- intellif_aihub-0.1.0/pyproject.toml +10 -0
- intellif_aihub-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import time
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Callable, List
|
|
5
|
+
|
|
6
|
+
_SENTINEL = Path(os.getenv("PRE_STOP_FILE", "/tmp/pre_stop"))
|
|
7
|
+
_flag = False # 缓存,防止反复读取 I/O
|
|
8
|
+
_callbacks: List[Callable[[], None]] = []
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _check_file() -> bool:
|
|
12
|
+
global _flag
|
|
13
|
+
if not _flag and _SENTINEL.exists():
|
|
14
|
+
_flag = True
|
|
15
|
+
for cb in _callbacks:
|
|
16
|
+
try:
|
|
17
|
+
cb()
|
|
18
|
+
except Exception as e:
|
|
19
|
+
print(f"[aihub] callback error: {e}", flush=True)
|
|
20
|
+
return _flag
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def receive_stop_command() -> bool:
|
|
24
|
+
return _check_file()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def register_callback(func: Callable[[], None]) -> None:
|
|
28
|
+
_callbacks.append(func)
|
|
29
|
+
import threading
|
|
30
|
+
def _watch():
|
|
31
|
+
while True:
|
|
32
|
+
if _check_file():
|
|
33
|
+
break
|
|
34
|
+
time.sleep(1)
|
|
35
|
+
|
|
36
|
+
threading.Thread(target=_watch, daemon=True).start()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aihub
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "intellif-aihub"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
requires-python = ">=3.7"
|
|
5
|
+
authors = [{name="Platform Team", email="aihub@example.com"}]
|
|
6
|
+
description = "Graceful stop helper based on file sentinel"
|
|
7
|
+
|
|
8
|
+
[build-system]
|
|
9
|
+
requires = ["setuptools>=61", "wheel"]
|
|
10
|
+
build-backend = "setuptools.build_meta"
|