From e274d74be2cf508ba873bc9caa3ab6541091edd2 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Mon, 21 Oct 2019 18:23:58 +0300 Subject: [PATCH] Wait for threads to exit after stopping them This fixes a race condition where the main thread would check if any internal errors happened and get back a 0 while a worker thread was still busy printing the internal error message before incrementing the counter. Fixes #320. My experiments show that this adds no perceptible delay to the script runtime (on Linux). More specifically, there already is an annoying perceptible delay of about 1 second, but it's not caused by this change. --- linkcheck/director/aggregator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/linkcheck/director/aggregator.py b/linkcheck/director/aggregator.py index 92538b14..2ba8ef12 100644 --- a/linkcheck/director/aggregator.py +++ b/linkcheck/director/aggregator.py @@ -199,6 +199,8 @@ class Aggregate (object): self.cancel() for t in self.threads: t.stop() + for t in self.threads: + t.join(timeout=1.0) @synchronized(_threads_lock) def is_finished (self):