mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-03-24 18:00:24 +00:00
support timeout in get() method
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3285 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
5eec9cf527
commit
a1905bdb22
1 changed files with 13 additions and 3 deletions
16
linkcheck/cache/urlqueue.py
vendored
16
linkcheck/cache/urlqueue.py
vendored
|
|
@ -49,7 +49,7 @@ class UrlQueue (Queue.Queue):
|
|||
self.checked = {}
|
||||
self.shutdown = False
|
||||
|
||||
def get (self):
|
||||
def get (self, timeout=None):
|
||||
"""
|
||||
Get first not-in-progress url from the queue and
|
||||
return it. If no such url is available return None. The
|
||||
|
|
@ -57,8 +57,18 @@ class UrlQueue (Queue.Queue):
|
|||
"""
|
||||
self.not_empty.acquire()
|
||||
try:
|
||||
while self._empty():
|
||||
self.not_empty.wait()
|
||||
if timeout is None:
|
||||
while self._empty():
|
||||
self.not_empty.wait()
|
||||
else:
|
||||
if timeout < 0:
|
||||
raise ValueError("'timeout' must be a positive number")
|
||||
endtime = time.time() + timeout
|
||||
while self._empty():
|
||||
remaining = endtime - time.time()
|
||||
if remaining <= 0.0:
|
||||
raise Empty
|
||||
self.not_empty.wait(remaining)
|
||||
url_data = self._get()
|
||||
key = url_data.cache_url_key
|
||||
if url_data.has_result:
|
||||
|
|
|
|||
Loading…
Reference in a new issue