Limit thread count if less than default.

This commit is contained in:
Arun Prakash Jana 2016-12-01 02:20:36 +05:30
parent 5dfa8ace47
commit 321fc05377
No known key found for this signature in database
GPG Key ID: A75979F35C080412

View File

@ -754,6 +754,8 @@ class BukuDb:
:param index: index of record to update, or 0 for all records
'''
global NUM_THREADS
if index == 0:
self.cur.execute('SELECT id, url FROM bookmarks WHERE \
flags & 1 != 1 ORDER BY id ASC')
@ -762,7 +764,8 @@ class BukuDb:
flags & 1 != 1', (index,))
resultset = self.cur.fetchall()
if not len(resultset):
recs = len(resultset)
if not recs:
logerr('No matching index or title immutable or empty DB')
return False
@ -774,6 +777,7 @@ class BukuDb:
def refresh(count, cond):
'''Inner function to fetch titles and update records
param count: dummy input to adhere to convention
param cond: threading condition object
'''
@ -824,6 +828,9 @@ class BukuDb:
done['value'] += 1
cond.notify()
if recs < NUM_THREADS:
NUM_THREADS = recs
for i in range(NUM_THREADS):
thread = threading.Thread(target=refresh, args=(i, cond))
thread.start()