fix: address review-bot findings on merged PRs (#593)

Squashed from PR #595. Closes #593.
This commit is contained in:
Vito Sansevero
2026-10-31 23:13:59 -07:00
parent 01a4f1d989
commit 85441aa637
10 changed files with 165 additions and 40 deletions
+4 -1
View File
@@ -113,7 +113,10 @@ def _start_daemon_observer(observer) -> None:
def start() -> None:
try:
observer.start()
except BaseException as e: # re-raised on the caller's thread
# BaseException on purpose: a KeyboardInterrupt or SystemExit raised
# by start() is not lost on this thread; _start_daemon_observer
# re-raises it on the caller's thread below.
except BaseException as e:
raised.append(e)
starter = threading.Thread(
+5 -5
View File
@@ -16,8 +16,9 @@ import sys
import threading
_lock = threading.Lock()
_trim = None
_looked_up = False
# Not looked up yet; after the lookup, the function or None.
_NOT_LOOKED_UP = object()
_trim = _NOT_LOOKED_UP
def _glibc() -> bool:
@@ -33,10 +34,9 @@ def _glibc() -> bool:
def _malloc_trim():
"""glibc's ``malloc_trim``, looked up once; None where there is none."""
global _trim, _looked_up
global _trim
with _lock:
if not _looked_up:
_looked_up = True
if _trim is _NOT_LOOKED_UP:
_trim = _lookup()
return _trim
+6 -4
View File
@@ -165,10 +165,12 @@ def _collect(func, items, futures):
and wait for its running ones, as the old per-call pool's exit did."""
try:
return _run_rest(func, items, futures)
except BaseException:
for future in futures:
future.cancel()
wait(futures)
except BaseException: # re-raised below, after the running items stop
# Wait only for what could not be cancelled (running or done). A
# future ``shutdown(cancel_futures=True)`` already cancelled stays
# CANCELLED, never notified, and ``wait`` would block on it forever
# (#593); ``cancel()`` is True for those as well.
wait([future for future in futures if not future.cancel()])
raise