Skip to content

Commit b93f5e1

Browse files
author
Bobby Impollonia
committed
Ensure ThreadPool is closed in setup_helpers
The ParallelCompile setup helper using a ThreadPool to enable its parallelism. It does not properly close the pool when it is done with it. This can lead to a "Exception ignored in: <function Pool.__del__..." message with traceback being printed at shutdown. Use pool.terminate() instead of context manager for Python 2.7 compatibility
1 parent 59aa998 commit b93f5e1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pybind11/setup_helpers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,12 @@ def _single_compile(obj):
466466
threads = 1
467467

468468
if threads > 1:
469-
for _ in ThreadPool(threads).imap_unordered(_single_compile, objects):
470-
pass
469+
pool = ThreadPool(threads)
470+
try:
471+
for _ in pool.imap_unordered(_single_compile, objects):
472+
pass
473+
finally:
474+
pool.terminate()
471475
else:
472476
for ob in objects:
473477
_single_compile(ob)

0 commit comments

Comments
 (0)