Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python thread stop

# how to kill threads
# using set/reset stop flag
 
import threading
import time
 
def run():
    while True:
        print('thread running')
        global stop_threads
        if stop_threads:
            break
 
stop_threads = False
t1 = threading.Thread(target = run)
t1.start()
time.sleep(1)
stop_threads = True
t1.join()
print('thread killed')
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #python #thread #stop
ADD COMMENT
Topic
Name
6+1 =