mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-23 09:20:30 +00:00
Improved thread lock handling.
This commit is contained in:
parent
2d55c87429
commit
982e13d193
6 changed files with 15 additions and 30 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue