Answer the question
In order to leave comments, you need to log in
How to stop all daemon threads on button click?
There is a STOP button in the interface, it is necessary that after pressing it, all demonic threads are completed
Answer the question
In order to leave comments, you need to log in
You can use the threading library, there is such an entity as event. Using event, you can send a signal to all threads, and threads receiving this signal can either suspend or self-destruct.
An example of usage is here:
https://www.bogotobogo.com/python/Multithread/pyth...
1) The easiest way to do this is using the multiprocessing library.
2) Something like this:
import multiprocessing
import time
def func(number):
for i in range(1, 10):
time.sleep(0.01)
print('Processing ' + str(number) + ': prints ' + str(number*i))
# list of all processes, so that they can be killed afterwards
all_processes = []
for i in range(0, 3):
process = multiprocessing.Process(target=func, args=(i,))
process.start()
all_processes.append(process)
# kill all processes after 0.03s
time.sleep(0.03)
for process in all_processes:
process.terminate()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question