【发布时间】:2017-08-10 01:18:54
【问题描述】:
我有 2 个函数需要根据用户设置相互调用。也就是说,如果用户重复打开它只需要继续运行直到手动停止,我有一个按钮。如何在不导致程序崩溃的无限循环错误的情况下执行此操作?
def T1_Timer(list):
msg = list[0]
global t1
T1_List = list
t1 = threading.Timer(MultiTimer2Settings.T1_Time, msg)
while t1.is_alive():
if not t1.is_alive():
return
else:
time.sleep(1)
Parent.SendTwitchMessage(msg)
T1_List.pop(0)
return T1_List
def DoRun1():
T1_List1 = []
T1_List2 = []
while not StopPressed:
T1_List1 = CheckList1(T1_List2)
T1_List2 = T1_Timer(T1_List1)
return
StopPressed = False
def StopButton():
global StopPressed
StopPressed = True
return
def CheckList1(T1_List=[]):
global t1
t1 = threading.Timer(MultiTimer2Settings.T1_Time, "")
if not t1.is_alive() and len(T1_List) <= 0:
if MultiTimer2Settings.T1M1_Enabled:
T1_List.append(MultiTimer2Settings.T1M1)
if MultiTimer2Settings.T1M2_Enabled:
T1_List.append(MultiTimer2Settings.T1M2)
if MultiTimer2Settings.T1M3_Enabled:
T1_List.append(MultiTimer2Settings.T1M3)
if MultiTimer2Settings.T1M4_Enabled:
T1_List.append(MultiTimer2Settings.T1M4)
if MultiTimer2Settings.T1M5_Enabled:
T1_List.append(MultiTimer2Settings.T1M5)
return T1_List
【问题讨论】:
-
无限循环不会导致崩溃。无限递归确实如此。
-
相互递归并使用结束条件。
标签: python function loops crash