我一直在研究跟踪游戏时间的程序,该程序从文本文件中读取,然后相应地设置计时器。我知道我设置它的方式可能会做得更好,但无论如何我就是这样做的。当我输入第一部分时,它将正确启动计时器,但是当我输入第二部分时,它似乎立即断开程序并抛出:“aborted(disconnected)”。
这是我的代码
import threading
from threading import Thread
import time
def test():
test = 2
while test > 1:
for z in range(0,-1,-1):
seconds1 = z % 1
time.sleep(1.0)
file = open("newfile.txt","r+") #opens file with name of "test.txt"
y = file.readline()
x = file.readline()
if x == "f" or x == "F":
if __name__ == '__main__':
Thread(target = test2).start()
print("Timer started for", y ,"Flash")
f = open("newfile.txt", "w+")
f.write(f.read().replace("f",""))
f.close()
file.close()
for f in range(300,-1,-1):
seconds = f % 301
print (seconds,y)
time.sleep(1.0)
print(str(y), "Flash is now up")
if x == "heal" or x == "Heal":
if __name__ == '__main__':
Thread(target = test2).start()
print("Timer started for", y ,"heal")
f = open("newfile.txt", "w+")
f.write(f.read().replace("heal","").replace("Heal",""))
f.close()
file.close()
for h in range(240,-1,-1):
seconds2 = h % 241
print (seconds2,y)
time.sleep(1.0)
print(str(y), "heal is now up")
if x == "exh" or x == "exhaust" or x == "Exhaust":
if __name__ == '__main__':
Thread(target = test2).start()
print("Timer started for", y ,"exhaust")
f = open("newfile.txt", "w+")
f.write(f.read().replace("exhaust","").replace("exh","").replace("exh",""))
f.close()
file.close()
for e in range(210,-1,-1):
seconds3 = e % 211
print (seconds3,y)
time.sleep(1.0)
print(str(y), "exhaust is now up")
if x == "ignite" or x == "Ignite":
if __name__ == '__main__':
Thread(target = test2).start()
print("Timer started for", y ,"ignite")
f = open("newfile.txt", "w+")
f.write(f.read().replace("ignite","").replace("Ignite",""))
f.close()
file.close()
for i in range(5,-1,-1):
seconds4 = i % 5
print (seconds4,y)
time.sleep(1.0)
print(y, "ignite is now up")
else:
file.close()
def test2():
test = 2
while test > 1:
for z in range(0,-1,-1):
seconds1 = z % 1
time.sleep(1.0)
file = open("newfile.txt","r+") #opens file with name of "test.txt"
y = file.readline()
x = file.readline()
if x == "f" or x == "F":
if __name__ == '__main__':
Thread(target = test3).start()
print("Timer started for", y ,"Flash")
f = open("newfile.txt", "w+")
f.write(f.read().replace("f",""))
f.close()
file.close()
for f in range(300,-1,-1):
seconds = f % 301
print (seconds,y)
time.sleep(1.0)
print(str(y), "Flash is now up")
if x == "heal" or x == "Heal":
if __name__ == '__main__':
Thread(target = test3).start()
print("Timer started for", y ,"heal")
f = open("newfile.txt", "w+")
f.write(f.read().replace("heal","").replace("Heal",""))
f.close()
file.close()
for h in range(240,-1,-1):
seconds2 = h % 241
print (seconds2,y)
time.sleep(1.0)
print(str(y), "heal is now up")
if x == "exh" or x == "exhaust" or x == "Exhaust":
if __name__ == '__main__':
Thread(target = test3).start()
print("Timer started for", y ,"exhaust")
f = open("newfile.txt", "w+")
f.write(f.read().replace("exhaust","").replace("exh","").replace("exh",""))
f.close()
file.close()
for e in range(210,-1,-1):
seconds3 = e % 211
print (seconds3,y)
time.sleep(1.0)
print(str(y), "exhaust is now up")
if x == "ignite" or x == "Ignite":
if __name__ == '__main__':
Thread(target = test3).start()
print("Timer started for", y ,"ignite")
f = open("newfile.txt", "w+")
f.write(f.read().replace("ignite","").replace("Ignite",""))
f.close()
file.close()
for i in range(5,-1,-1):
seconds4 = i % 5
print (seconds4,y)
time.sleep(1.0)
print(y, "ignite is now up")
else:
file.close()
def test3():
test = -1
while test > 1:
for z in range(0,-1,-1):
seconds1 = z % 1
time.sleep(1.0)
file = open("newfile.txt","r+") #opens file with name of "test.txt"
y = file.readline()
x = file.readline()
if x == "f" or x == "F":
if __name__ == '__main__':
Thread(target = test4).start()
print("Timer started for", y ,"Flash")
f = open("newfile.txt", "w+")
f.write(f.read().replace("f",""))
f.close()
file.close()
for f in range(300,-1,-1):
seconds = f % 301
print (seconds,y)
time.sleep(1.0)
print(str(y), "Flash is now up")
if x == "heal" or x == "Heal":
if __name__ == '__main__':
Thread(target = test4).start()
print("Timer started for", y ,"heal")
f = open("newfile.txt", "w+")
f.write(f.read().replace("heal","").replace("Heal",""))
f.close()
file.close()
for h in range(240,-1,-1):
seconds2 = h % 241
print (seconds2,y)
time.sleep(1.0)
print(str(y), "heal is now up")
if x == "exh" or x == "exhaust" or x == "Exhaust":
if __name__ == '__main__':
Thread(target = test4).start()
print("Timer started for", y ,"exhaust")
f = open("newfile.txt", "w+")
f.write(f.read().replace("exhaust","").replace("exh","").replace("exh",""))
f.close()
file.close()
for e in range(210,-1,-1):
seconds3 = e % 211
print (seconds3,y)
time.sleep(1.0)
print(str(y), "exhaust is now up")
if x == "ignite" or x == "Ignite":
if __name__ == '__main__':
Thread(target = test4).start()
print("Timer started for", y ,"ignite")
f = open("newfile.txt", "w+")
f.write(f.read().replace("ignite","").replace("Ignite",""))
f.close()
file.close()
for i in range(5,-1,-1):
seconds4 = i % 5
print (seconds4,y)
time.sleep(1.0)
print(y, "ignite is now up")
else:
file.close()
def test4():
test = 2
while test > 1:
for z in range(0,-1,-1):
seconds1 = z % 1
time.sleep(1.0)
file = open("newfile.txt","r+") #opens file with name of "test.txt"
y = file.readline()
x = file.readline()
if x == "f" or x == "F":
if __name__ == '__main__':
Thread(target = test5).start()
print("Timer started for", y ,"Flash")
f = open("newfile.txt", "w+")
f.write(f.read().replace("f",""))
f.close()
file.close()
for f in range(300,-1,-1):
seconds = f % 301
print (seconds,y)
time.sleep(1.0)
print(str(y), "Flash is now up")
if x == "heal" or x == "Heal":
if __name__ == '__main__':
Thread(target = test5).start()
print("Timer started for", y ,"heal")
f = open("newfile.txt", "w+")
f.write(f.read().replace("heal","").replace("Heal",""))
f.close()
file.close()
for h in range(240,-1,-1):
seconds2 = h % 241
print (seconds2,y)
time.sleep(1.0)
print(str(y), "heal is now up")
if x == "exh" or x == "exhaust" or x == "Exhaust":
if __name__ == '__main__':
Thread(target = test5).start()
print("Timer started for", y ,"exhaust")
f = open("newfile.txt", "w+")
f.write(f.read().replace("exhaust","").replace("exh","").replace("exh",""))
f.close()
file.close()
for e in range(210,-1,-1):
seconds3 = e % 211
print (seconds3,y)
time.sleep(1.0)
print(str(y), "exhaust is now up")
if x == "ignite" or x == "Ignite":
if __name__ == '__main__':
Thread(target = test5).start()
print("Timer started for", y ,"ignite")
f = open("newfile.txt", "w+")
f.write(f.read().replace("ignite","").replace("Ignite",""))
f.close()
file.close()
for i in range(5,-1,-1):
seconds4 = i % 5
print (seconds4,y)
time.sleep(1.0)
print(y, "ignite is now up")
else:
file.close()
def test5():
test = 2
while test > 1:
for z in range(0,-1,-1):
seconds1 = z % 1
time.sleep(1.0)
file = open("newfile.txt","r+") #opens file with name of "test.txt"
y = file.readline()
x = file.readline()
if x == "f" or x == "F":
print("Timer started for", y ,"Flash")
f = open("newfile.txt", "w+")
f.write(f.read().replace("f",""))
f.close()
file.close()
for f in range(300,-1,-1):
seconds = f % 301
print (seconds,y)
time.sleep(1.0)
print(str(y), "Flash is now up")
if x == "heal" or x == "Heal":
print("Timer started for", y ,"heal")
f = open("newfile.txt", "w+")
f.write(f.read().replace("heal","").replace("Heal",""))
f.close()
file.close()
for h in range(240,-1,-1):
seconds2 = h % 241
print (seconds2,y)
time.sleep(1.0)
print(str(y), "heal is now up")
if x == "exh" or x == "exhaust" or x == "Exhaust":
print("Timer started for", y ,"exhaust")
f = open("newfile.txt", "w+")
f.write(f.read().replace("exhaust","").replace("exh","").replace("exh",""))
f.close()
file.close()
for e in range(210,-1,-1):
seconds3 = e % 211
print (seconds3,y)
time.sleep(1.0)
print(str(y), "exhaust is now up")
if x == "ignite" or x == "Ignite":
print("Timer started for", y ,"ignite")
f = open("newfile.txt", "w+")
f.write(f.read().replace("ignite","").replace("Ignite",""))
f.close()
file.close()
for i in range(5,-1,-1):
seconds4 = i % 5
print (seconds4,y)
time.sleep(1.0)
print(y, "ignite is now up")
else:
file.close()