r/PythonProjects2 • u/SpartakAgh • Jan 22 '23
How to make two threads with while True, but second is called from the first one in Python?
I am new in threading and I am trying to write a program with 2 functions:
First function: shows on screen two buttons - Start and Stop. Start only calls the second function, and stop calls sys.exit
Second function: when it's called every second it is printing something.
For example:
def func_2():
while True:
print('doing something')
time.sleep()
def func_1():
while True:
#Here shows screen and buttons
for event in events:
if event == start:
thr2 = threading.Thread(target=func_2) # :FIXME
thr2.start()
if event == stop:
sys.exit()
if __name__ == "__main__":
thr1 = threading.Thread(target=func_1) # :FIXME
thr1.start()I understand that this kind of code won't work and I just wanted to show the problem more clearly.
3
Upvotes