Skip to content

Fix multiprocessing Pool shutdown issue on Python 3.13+#249

Merged
zblz merged 2 commits intomainfrom
fix/245-multiprocessing-pool-shutdown
Feb 13, 2026
Merged

Fix multiprocessing Pool shutdown issue on Python 3.13+#249
zblz merged 2 commits intomainfrom
fix/245-multiprocessing-pool-shutdown

Conversation

@zblz
Copy link
Copy Markdown
Owner

@zblz zblz commented Feb 12, 2026

Summary

  • Fixes the OSError: [Errno 9] Bad file descriptor that occurs on Python 3.13+ when the multiprocessing Pool created in get_sampler is garbage-collected without being properly shut down
  • Creates the pool separately and skips it entirely for single-threaded runs (threads=1), passing pool=None to emcee (which runs serially)
  • Attaches the pool reference to the sampler via _naima_pool and explicitly calls close()/join() after run_sampler completes

Closes #245

@zblz zblz force-pushed the fix/245-multiprocessing-pool-shutdown branch from 5fa84f5 to 28a99a1 Compare February 12, 2026 17:33
Create the pool separately and skip it for single-threaded runs
(threads=1). Attach the pool reference to the sampler and explicitly
close/join it after run_sampler finishes, preventing the OSError
"Bad file descriptor" that occurs when Pool.__del__ fires on an
already-closed pipe.

Closes #245
@zblz zblz force-pushed the fix/245-multiprocessing-pool-shutdown branch from 28a99a1 to a1b3e59 Compare February 12, 2026 17:35
@zblz zblz force-pushed the fix/245-multiprocessing-pool-shutdown branch from 8a2d787 to c9b5792 Compare February 13, 2026 09:01
@zblz zblz enabled auto-merge February 13, 2026 09:02
@zblz zblz merged commit ba3bbbd into main Feb 13, 2026
13 checks passed
@zblz zblz deleted the fix/245-multiprocessing-pool-shutdown branch February 13, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiprocessing shutdown issue

1 participant