"aborted (disconnected)" in python 3.4
<p>I've been working on a program to track times for a game, which reads from a text file then sets up timers accordingly. I know the way I've set it up can probably be done much better, but this is how I've done it anyway. When I input the first part, it will start the timer correctly but when I input the second part it seems to immediately disconnect the program and throw this: "aborted (disconnected)". </p>

<p>This is my code</p>

<pre><code>import threading
from threading import Thread
import time

def test():
        test = 2
        while test &gt; 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 &gt; 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 &gt; 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 &gt; 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 &gt; 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()
</code></pre>