我有两个功能需要根据用户设置相互调用。也就是说,如果用户重复打开它,只需要继续操作直到手动停止,我有一个按钮。如何在不造成程序崩溃的无限循环错误的情况下执行此操作?
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
答案 0 :(得分:0)
只需使用while
循环:
stopButtonPressed = False
var1 = <initial value>
while not stopButtonPressed:
var2 = function1(var1)
var1 = function2(var2)
它们应该返回它们传递给另一个函数的值,而不是每个函数调用另一个函数。然后,您可以将它们放在变量中,并在连续调用中传递它们。
答案 1 :(得分:0)
类似这样的事情
Break = 0
Function1():
test = 12
print test
return
Function1():
test1 = 13
print test2
return
while Break < 15:
Break += 1
Function1()
Function2()
使用一个函数调用另一个函数将不在循环中,因此这样做是最简单的选项
尝试运行它!