Skip to content

Commit

Permalink
feat: cleanup threadpool
Browse files Browse the repository at this point in the history
  • Loading branch information
jlwalke2 committed Aug 29, 2024
1 parent 82a9bec commit 02ceda2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/sasctl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,13 @@ def __init__(self, obj, session=None, threads=4):
# Store the current items to iterate over
self._obj = obj

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
if self._pool is not None:
self._pool.shutdown(wait=False, cancel_futures=True)

def __next__(self):
if self._pool is None:
self._pool = concurrent.futures.ThreadPoolExecutor(
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/test_pageiterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ def test_paging_required(paging):
"""Requests should be made to retrieve additional pages."""
obj, items, _ = paging

pager = PageIterator(obj)
init_count = pager._start

for i, page in enumerate(pager):
for j, item in enumerate(page):
if i == 0:
item_idx = j
else:
# Account for initial page size not necessarily being same size
# as additional pages
item_idx = init_count + (i - 1) * pager._limit + j
target = RestObj(items[item_idx])
assert item.name == target.name
with PageIterator(obj) as pager:
init_count = pager._start

for i, page in enumerate(pager):
for j, item in enumerate(page):
if i == 0:
item_idx = j
else:
# Account for initial page size not necessarily being same size
# as additional pages
item_idx = init_count + (i - 1) * pager._limit + j
target = RestObj(items[item_idx])
assert item.name == target.name

0 comments on commit 02ceda2

Please sign in to comment.