Reputation: 443
I use a thread pool and and I submit some tasks to be proccessed.
Sometimes a server that I ping or my internet connection could be down. This can be determined by any of the running threads.
In that case I would like the thread that detected the error to notify the others to pause their execution until the error is fixed.
Do you know how is this possible?
I add to the above. The ideal solution would be : when a threads detects the program to send a message to all other threads to wait. Also it should notify an external server and after receiving that everything is ok from the server to send again a signal to the other threads to continue the work.
Upvotes: 0
Views: 594
Reputation: 443
I found it using threading.Event
I just have an event
event = Event()
and I use the
event.wait()
In the beggining I
event.set()
when a thread detects an error it
event.clear()
and the threads are waiting until
event.set()
This seems to work
Upvotes: 2