Skip to content

Commit

Permalink
Revert to default mpcontext
Browse files Browse the repository at this point in the history
Use threadpoolctl to protect against deadlocks.
  • Loading branch information
nlgranger committed Nov 23, 2023
1 parent 23c6922 commit 2642be6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
"Intended Audience :: Science/Research",
]
dynamic = ["version"]
dependencies = ["tblib"]
dependencies = ["tblib", "threadpoolctl"]

[project.optional-dependencies]
tests = ["pytest", "pytest-timeout", "numpy", "pytest-coverage"]
Expand Down
8 changes: 5 additions & 3 deletions seqtools/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import io
import itertools
import multiprocessing
import os
Expand All @@ -14,6 +13,8 @@
from abc import ABC, abstractmethod
from multiprocessing import sharedctypes

import threadpoolctl

from tblib import pickling_support

from .C.refcountedbuffer import RefCountedBuffer
Expand Down Expand Up @@ -63,7 +64,7 @@ def __init__(self, seq, num_workers=0, buffer_size=10, init_fn=None, shm_size=0)
self.free_shm_slots = set()

# initialize workers
mp_ctx = multiprocessing.get_context(method="spawn") # spawn is OpenMP-friendly
mp_ctx = multiprocessing.get_context()
self.job_queue = mp_ctx.Queue()
self.result_pipes = []

Expand All @@ -85,7 +86,8 @@ def __init__(self, seq, num_workers=0, buffer_size=10, init_fn=None, shm_size=0)
daemon=True,
)
old_sig_hdl = signal.signal(signal.SIGINT, signal.SIG_IGN)
worker.start()
with threadpoolctl.threadpool_limits(limits=1):
worker.start()
signal.signal(signal.SIGINT, old_sig_hdl)
tx.close()

Expand Down

0 comments on commit 2642be6

Please sign in to comment.