Skip to content

Commit 331b11e

Browse files
committed
Making safe_get safer
1 parent c53635d commit 331b11e

2 files changed

Lines changed: 4 additions & 9 deletions

File tree

giskard/utils/worker_pool.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def safe_get(self, queue: Queue, timeout: float = 1) -> Tuple[Any, bool]:
189189
result = queue.get(timeout=timeout)
190190
except Empty:
191191
result = None
192-
except ValueError as e:
192+
except (ValueError, OSError) as e:
193193
# If queue is closed
194194
if not self.terminated():
195195
LOGGER.error("Queue is closed, and executor not in final state")
@@ -314,7 +314,7 @@ def shutdown(self, wait=True, *, cancel_futures=True, timeout: float = 5, force=
314314
if not force:
315315
self._state = PoolState.STOPPED
316316
# Cleaning up processes
317-
exit_codes = _stop_processes(p_list, timeout=1)
317+
exit_codes = _stop_processes(p_list, timeout=timeout)
318318
self._manager.shutdown()
319319
return exit_codes
320320

@@ -387,6 +387,3 @@ def _killer_thread(
387387

388388
if exception is not None:
389389
raise exception
390-
391-
if executor.terminated():
392-
return

tests/test_worker_pool.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ def many_worker_pool():
1616
pool = WorkerPoolExecutor(nb_workers=4)
1717
sleep(3)
1818
yield pool
19-
pool.shutdown(wait=True)
20-
pool.shutdown(wait=False, force=True)
19+
pool.shutdown(wait=True, force=True, timeout=10)
2120

2221

2322
@pytest.fixture(scope="function")
2423
def one_worker_pool():
2524
pool = WorkerPoolExecutor(nb_workers=1)
2625
sleep(3)
2726
yield pool
28-
pool.shutdown(wait=True)
29-
pool.shutdown(wait=False, force=True)
27+
pool.shutdown(wait=True, force=True, timeout=10)
3028

3129

3230
@pytest.mark.concurrency

0 commit comments

Comments
 (0)