fix: address review-bot findings on merged PRs (#593)
Squashed from PR #595. Closes #593.
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user