diff --git a/doc/changelog.txt b/doc/changelog.txt index 1b400bfb..ac9bb8a4 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -13,6 +13,7 @@ Fixes: Changes: - gui: Use Alt-key shortcuts for menu entries. +- checking: Improved thread locking and reduce calls to time.sleep(). Features: - checking: Added support for Google Chrome bookmark files. diff --git a/linkcheck/director/__init__.py b/linkcheck/director/__init__.py index aabaed3f..1ba215ad 100644 --- a/linkcheck/director/__init__.py +++ b/linkcheck/director/__init__.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2006-2010 Bastian Kleineidam +# Copyright (C) 2006-2011 Bastian Kleineidam # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,7 +17,6 @@ """ Management of checking a queue of links with several threads. """ -import time import os import thread import urlparse @@ -158,18 +157,13 @@ def check_url (aggregate): """Helper function waiting for URL queue.""" while True: try: - aggregate.urlqueue.join(timeout=0.5) + aggregate.urlqueue.join(timeout=30) break except urlqueue.Timeout: - # Since urlqueue.join() is not interruptable, add a timeout - # and a one-second slumber. - time.sleep(1) + # Cleanup threads every 30 seconds aggregate.remove_stopped_threads() if not aggregate.threads: break - if aggregate.wanted_stop: - # some other thread wants us to stop - raise KeyboardInterrupt def interrupt (aggregate): diff --git a/linkcheck/director/checker.py b/linkcheck/director/checker.py index 47120025..05182a3c 100644 --- a/linkcheck/director/checker.py +++ b/linkcheck/director/checker.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2006-2010 Bastian Kleineidam +# Copyright (C) 2006-2011 Bastian Kleineidam # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -45,10 +45,8 @@ class Checker (task.CheckedTask): def run_checked (self): """Check URLs in the queue.""" - while True: + while not self.stopped(0): self.check_url() - if self.stopped(): - break def check_url (self): """Try to get URL data from queue and check it.""" diff --git a/linkcheck/director/cleanup.py b/linkcheck/director/cleanup.py index 7be5f4ec..5fcd87d5 100644 --- a/linkcheck/director/cleanup.py +++ b/linkcheck/director/cleanup.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2010 Bastian Kleineidam +# Copyright (C) 2007-2011 Bastian Kleineidam # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -32,11 +32,5 @@ class Cleanup (task.CheckedTask): self.start_time = time.time() self.setName("Cleanup") # clean every 15 seconds - wait_seconds = 15 - waitfor = range(wait_seconds*10) - while True: - for dummy in waitfor: - time.sleep(0.1) - if self.stopped(): - return + while not self.stopped(15): self.connections.remove_expired() diff --git a/linkcheck/director/status.py b/linkcheck/director/status.py index 8bd4cc7c..1f749b97 100644 --- a/linkcheck/director/status.py +++ b/linkcheck/director/status.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2006-2010 Bastian Kleineidam +# Copyright (C) 2006-2011 Bastian Kleineidam # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,12 +33,7 @@ class Status (task.CheckedTask): """Print periodic status messages.""" self.start_time = time.time() self.setName("Status") - waitfor = range(self.wait_seconds*10) - while True: - for dummy in waitfor: - time.sleep(0.1) - if self.stopped(): - return + while not self.stopped(self.wait_seconds): self.log_status() def log_status (self): diff --git a/linkcheck/threader.py b/linkcheck/threader.py index ea68a764..ff0bf0e1 100644 --- a/linkcheck/threader.py +++ b/linkcheck/threader.py @@ -78,6 +78,9 @@ class StoppableThread (threading.Thread): """Set stop event.""" self._stop.set() - def stopped (self): + def stopped (self, timeout=None): """Return True if stop event is set.""" - return self._stop.isSet() + self._stop.wait(timeout) + # XXX on Python >= 2.7 the result from wait() can be returned + # directly. + return self._stop.is_set()