mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Move join_with_timeout into the utils module
This commit is contained in:
parent
e60dce0133
commit
8cc9440847
@ -8,7 +8,6 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
import itertools, operator, os
|
import itertools, operator, os
|
||||||
from types import MethodType
|
from types import MethodType
|
||||||
from time import time
|
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
from Queue import LifoQueue
|
from Queue import LifoQueue
|
||||||
from functools import wraps, partial
|
from functools import wraps, partial
|
||||||
@ -23,6 +22,7 @@ from PyQt4.Qt import (
|
|||||||
|
|
||||||
from calibre import fit_image, prints, prepare_string_for_xml
|
from calibre import fit_image, prints, prepare_string_for_xml
|
||||||
from calibre.ebooks.metadata import fmt_sidx
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
|
from calibre.utils import join_with_timeout
|
||||||
from calibre.gui2 import gprefs, config
|
from calibre.gui2 import gprefs, config
|
||||||
from calibre.gui2.library.caches import CoverCache, ThumbnailCache
|
from calibre.gui2.library.caches import CoverCache, ThumbnailCache
|
||||||
from calibre.utils.config import prefs, tweaks
|
from calibre.utils.config import prefs, tweaks
|
||||||
@ -482,17 +482,6 @@ class CoverDelegate(QStyledItemDelegate):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def join_with_timeout(q, timeout=2):
|
|
||||||
q.all_tasks_done.acquire()
|
|
||||||
try:
|
|
||||||
endtime = time() + timeout
|
|
||||||
while q.unfinished_tasks:
|
|
||||||
remaining = endtime - time()
|
|
||||||
if remaining <= 0.0:
|
|
||||||
raise RuntimeError('Waiting for queue to clear timed out')
|
|
||||||
q.all_tasks_done.wait(remaining)
|
|
||||||
finally:
|
|
||||||
q.all_tasks_done.release()
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# The View {{{
|
# The View {{{
|
||||||
|
@ -7,3 +7,19 @@ __docformat__ = 'restructuredtext en'
|
|||||||
Miscelleaneous utilities.
|
Miscelleaneous utilities.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
def join_with_timeout(q, timeout=2):
|
||||||
|
''' Join the queue q with a specified timeout. Blocks until all tasks on
|
||||||
|
the queue are done or times out with a runtime error. '''
|
||||||
|
q.all_tasks_done.acquire()
|
||||||
|
try:
|
||||||
|
endtime = time() + timeout
|
||||||
|
while q.unfinished_tasks:
|
||||||
|
remaining = endtime - time()
|
||||||
|
if remaining <= 0.0:
|
||||||
|
raise RuntimeError('Waiting for queue to clear timed out')
|
||||||
|
q.all_tasks_done.wait(remaining)
|
||||||
|
finally:
|
||||||
|
q.all_tasks_done.release()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user