Search
 
SCRIPT & CODE EXAMPLE
 

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')
Comment

how to stop thread python

import time
from threading import Thread

def doit(id=0):
    doit.stop=0
    print("start id:%d"%id)
    while 1:
        time.sleep(1)
        print(".")
        if doit.stop==id:
            doit.stop=0
            break
    print("end thread %d"%id)

t5=Thread(target=doit, args=(5,))
t6=Thread(target=doit, args=(6,))

t5.start() ; t6.start()
time.sleep(2)
doit.stop =5  #kill t5
time.sleep(2)
doit.stop =6  #kill t6
Comment

PREVIOUS NEXT
Code Example
Python :: how to find permutation of numbers in python 
Python :: python split by first match 
Python :: list deep copy 
Python :: write the output of a function in a txt file 
Python :: install python3 in ubuntu 
Python :: install virtual environments_brew 
Python :: pandas fillna with another column 
Python :: go to line in python 
Python :: if settings.debug 
Python :: python numpy delete element from array 
Python :: How to store the input from the text box in python 
Python :: skewness removal 
Python :: print string and variable python 
Python :: fibonacci recursive python 
Python :: pandas dataframe first rows 
Python :: Convert column as array to column as string before saving to csv 
Python :: destroy label tkinter 
Python :: pytorch older versions 
Python :: import turtle as t 
Python :: What is the use of f in python? 
Python :: envScriptsactivate.ps1 : File 
Python :: discord bot python time delay 
Python :: how to show mean values on histogram in seaborn 
Python :: cv2 imwrite 
Python :: python png library 
Python :: how to make python code faster 
Python :: creating dataframe 
Python :: apply on dataframe access multiple columns 
Python :: python run code at the same time 
Python :: record audio with processing python 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =