Skip to content

Commit 9187508

Browse files
committed
Fix SearchEngine.search with limit
1 parent b8fa12f commit 9187508

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

webscrapbook/scrapbook/search.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,22 @@ def run(self):
522522
def search(self):
523523
results = self.search_books()
524524
limit = self.query.limit
525+
525526
if limit >= 0:
526527
i = 0
527528
for item in results:
528529
i += 1
529530
if i > limit:
530531
break
531532
yield item
533+
534+
# In some Python implementation (e.g. PyPy with Python 3.11)
535+
# returning from this function doesn't close results automatically,
536+
# causing the acquired lock not released.
537+
results.close()
538+
532539
return
540+
533541
yield from results
534542

535543
def search_books(self):

0 commit comments

Comments
 (0)