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 :: xarray get number of lat lon 
Python :: pairwise function python 
Python :: turtle graphics documentation|pensize 
Python :: remove word from string in python 
Python :: super in django manager 
Python :: find array length in python 
Python :: wifite subsystem 
Python :: python remove file with pattern 
Python :: can serializer returns an object in django 
Python :: box plot in seaborn 
Python :: tree python 
Python :: how to find uncommon records of two dataframes 
Python :: create array of specific size python 
Python :: numpy random 
Python :: how to print during multiprocessing 
Python :: matrix diagonal sum python 
Python :: python how to drop columns from dataframe 
Python :: word counter python 
Python :: python string iterate 3 characters at a time 
Python :: import pyautogui 
Python :: confusion matrix with seaborn heatmap 
Python :: pandas df.to_csv() accent in columns name 
Python :: write string python 
Python :: python find index of closest value in list 
Python :: To create a SparkSession 
Python :: how to show installed tkinter fonts 
Python :: pytorch dill model save 
Python :: pytube get highest resolution 
Python :: python animation 
Python :: unsupervised knn 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =