Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python stop daemon thread

# function that will be in a thread
def my_func(msg_queue, stop_event):
    while not stop_event.is_set(): # <============= will stop if stop_event is set
        msg_queue.put("hi")
        sleep(0.1)

stop_event= threading.Event()
p = Thread(target=my_func, args=(msg_queue, stop_event))
p.start()

stop_event.set() # <====== to stop the thread
Comment

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

PREVIOUS NEXT
Code Example
Python :: how to show webcam in opencv 
Python :: how to find second maximum element of an array python 
Python :: python read lines from text file 
Python :: convert set to list python time complexity 
Python :: boolean python meaning for idiots 
Python :: Installing python module from within code 
Python :: pandas add rows from df to another 
Python :: iterar una lista en python 
Python :: my pygame window wont stay open 
Python :: write file with python 
Python :: remove python2 centos 
Python :: python element wise multiplication list 
Python :: np.loadtext 
Python :: pandas conditional replace values in a series 
Python :: python how to make something run once 
Python :: convert number to binary in python 
Python :: How to set up flash message in html template in flask app 
Python :: encode labels in scikit learn 
Python :: how to check if index is out of range python 
Python :: install python selenium webdriver 
Python :: how to address a column in a 2d array python 
Python :: median absolute deviation scipy 
Python :: how to get seconds from datetime in python 
Python :: how to format integer to two digit in python 
Python :: python datetime add one week 
Python :: check string equal with regular expression python 
Python :: extract minutes from timedelta python 
Python :: how to open excel with more than one sheetpython 
Python :: location of last row dataframe 
Python :: python regex find first 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =