From 5f9c11b794c49c967792d5185eb33854d87dfb74 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sun, 24 Oct 2010 01:40:32 +0200 Subject: [PATCH] Tune timeout values to close threads faster on exit. --- doc/changelog.txt | 2 ++ linkcheck/director/__init__.py | 2 +- linkcheck/director/aggregator.py | 2 +- linkcheck/director/checker.py | 3 +-- linkcheck/director/cleanup.py | 9 +++++---- linkcheck/director/status.py | 4 ++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/changelog.txt b/doc/changelog.txt index 8f46041e..8d8aab0b 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -13,6 +13,8 @@ Changes: - install: Copy and execute the Microsoft Visual C runtime DLL installer. This solves startup error on WinXP systems that don't have this DLL installed. +- checking: Tune timeout values to close threads faster on exit. + Closes: SF bug #3087944 Features: - gui: Added "View parent URL online" context menu action to display diff --git a/linkcheck/director/__init__.py b/linkcheck/director/__init__.py index 1a8fc327..4d946163 100644 --- a/linkcheck/director/__init__.py +++ b/linkcheck/director/__init__.py @@ -144,7 +144,7 @@ def check_url (aggregate): """Helper function waiting for URL queue.""" while True: try: - aggregate.urlqueue.join(timeout=1) + aggregate.urlqueue.join(timeout=0.5) break except urlqueue.Timeout: # Since urlqueue.join() is not interruptable, add a timeout diff --git a/linkcheck/director/aggregator.py b/linkcheck/director/aggregator.py index 20380509..6ec082d0 100644 --- a/linkcheck/director/aggregator.py +++ b/linkcheck/director/aggregator.py @@ -88,7 +88,7 @@ class Aggregate (object): assert self.urlqueue.empty() for t in self.threads: t.stop() - t.join(2) + t.join(0.5) if t.isAlive(): log.warn(LOG_CHECK, "Thread %s still active", t) self.connections.clear() diff --git a/linkcheck/director/checker.py b/linkcheck/director/checker.py index 2b2981b2..81140bf4 100644 --- a/linkcheck/director/checker.py +++ b/linkcheck/director/checker.py @@ -17,7 +17,6 @@ """ URL checking functions. """ -import time from . import task from ..cache import urlqueue @@ -62,7 +61,7 @@ class Checker (task.CheckedTask): self.urlqueue.task_done(url_data) self.setName(self.origname) except urlqueue.Empty: - time.sleep(0.1) + pass def check_url_data (self, url_data): """Check one URL data instance.""" diff --git a/linkcheck/director/cleanup.py b/linkcheck/director/cleanup.py index 4163b5cc..7be5f4ec 100644 --- a/linkcheck/director/cleanup.py +++ b/linkcheck/director/cleanup.py @@ -31,11 +31,12 @@ class Cleanup (task.CheckedTask): """Print periodic status messages.""" self.start_time = time.time() self.setName("Cleanup") + # clean every 15 seconds + wait_seconds = 15 + waitfor = range(wait_seconds*10) while True: - # clean every 30 seconds - for dummy in range(30): - time.sleep(1) - # check every second if we have stopped + for dummy in waitfor: + time.sleep(0.1) if self.stopped(): return self.connections.remove_expired() diff --git a/linkcheck/director/status.py b/linkcheck/director/status.py index 5de06b2d..8bd4cc7c 100644 --- a/linkcheck/director/status.py +++ b/linkcheck/director/status.py @@ -33,10 +33,10 @@ class Status (task.CheckedTask): """Print periodic status messages.""" self.start_time = time.time() self.setName("Status") - waitfor = range(self.wait_seconds) + waitfor = range(self.wait_seconds*10) while True: for dummy in waitfor: - time.sleep(1) + time.sleep(0.1) if self.stopped(): return self.log_status()