So I'm doing some testing with threads and I realised I could not stop and then start a thread. I could stop it, but starting it again was the issue.
I want a script that adds 1 to a var when it is on then its stops when off by pressing shift to turn on and off.
I have the detecting shift working (it is on another part of my code), but I just need to find out how to stop and start threads
Here is my test code:
from threading import Thread as th
import time as t
var = 0
def testDef():
global var
var += 1:
t.sleep(1)
test = th(target = testDef)
test.start()
while True:
menu = input("On, Off, Show Var")
if menu == "On":
test.start()
elif menu == "Off":
test._stop():
elif menu == "S":
print(var)
I know there are a few errors, but I mainly need the on and off threading to work. Thanks, Jeff.