+ 3

Why doesn't It start threads again? (Python)

When I try to make threads go again, the script prints the output but actually doesn't start them (the threads). I writed down below the code to let a clear understanding of the problem (marked with #): import threading import time block = False def numera(name): name = str(threading.current_thread()) global block i = 0 while True: if block is False: print(name + " " + str(i)) i += 1 time.sleep(0.1) if i > 100: block = True break else: break name = 1 def handle_session(): global name for num in range(3): print("STARTING THREAD") threading.Thread(target=numera, args=(str(name),)).start() name += 1 handle_session() while True: name = 1 time.sleep(1) print(threading.current_thread(), block) if block is True: print("RESTART THREADS") handle_session() #THERE'S THE PROBLEM HERE block = False Plz Help Me :)))

14th Aug 2019, 4:43 PM
Giordano Fratti
Giordano Fratti - avatar
4 Antworten
+ 3
I corrected your code and used comments to explain what I changed: https://code.sololearn.com/caz80LwGG41u/#py
15th Aug 2019, 1:29 PM
Thoq!
Thoq! - avatar
+ 3
No problem. I have always wanted to make myself more acquainted with "threading". Let me know if you need any further explanations.
15th Aug 2019, 2:14 PM
Thoq!
Thoq! - avatar
+ 1
Thanks man, when I come home I'll try It on my PC and then I'll implement that on my code. Now I've quickly seen It on this platform and it seems work :)) Thanks againn
15th Aug 2019, 2:05 PM
Giordano Fratti
Giordano Fratti - avatar
+ 1
Oki Doki 😄
15th Aug 2019, 3:06 PM
Giordano Fratti
Giordano Fratti - avatar