-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathinterrupt.py
64 lines (51 loc) · 1.62 KB
/
interrupt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import signal
import locale
def interrupt_handler(signum, frame):
print("Process interrupted")
sys.exit(0)
class AnyType(str):
"""A special class that is always equal in not equal comparisons. Credit to pythongosssss"""
def __ne__(self, __value: object) -> bool:
return False
any_type = AnyType("*")
class interrupt_loop:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"is_enable": ("BOOLEAN", {"default":False}),
"any": (any_type, {}),
}
}
RETURN_TYPES = (any_type,)
RETURN_NAMES = ("any",)
FUNCTION = "time"
OUTPUT_NODE = True
CATEGORY = "大模型派对(llm_party)/工作流(workflow)"
def time(self,any,is_enable=False):
if is_enable == False:
return (any,)
else:
signal.signal(signal.SIGINT, interrupt_handler)
signal.raise_signal(signal.SIGINT) # 直接中断进程
return ()
NODE_CLASS_MAPPINGS = {"interrupt_loop": interrupt_loop}
# 获取系统语言
lang = locale.getdefaultlocale()[0]
import os
import sys
current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
config_path = os.path.join(current_dir, "config.ini")
import configparser
config = configparser.ConfigParser()
config.read(config_path)
try:
language = config.get("API_KEYS", "language")
except:
language = ""
if language == "zh_CN" or language=="en_US":
lang=language
if lang == "zh_CN":
NODE_DISPLAY_NAME_MAPPINGS = {"interrupt_loop": "中断循环"}
else:
NODE_DISPLAY_NAME_MAPPINGS = {"interrupt_loop": "Interrupt Loop"}