Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #stop #daemon #thread
ADD COMMENT
Topic
Name
2+8 =