Skip to content

Commit

Permalink
Merge pull request #246 from zhonge/subprocess-spawn
Browse files Browse the repository at this point in the history
Spawn rather than fork subprocesses to avoid OOM
  • Loading branch information
zhonge committed Mar 26, 2023
2 parents a5bd4c0 + aa44d5f commit 2b02e88
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cryodrgn/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import multiprocessing as mp
import os
from multiprocessing import Pool
import multiprocessing
import logging
from torch.utils import data

Expand Down Expand Up @@ -186,7 +186,8 @@ def __init__(
max_threads = min(max_threads, mp.cpu_count())
if max_threads > 1:
logger.info(f"Spawning {max_threads} processes")
with Pool(max_threads) as p:
context = multiprocessing.get_context("spawn")
with context.Pool(max_threads) as p:
particles = pp.asarray(
p.map(fft.ht2_center, particles), dtype=pp.float32
)
Expand Down

0 comments on commit 2b02e88

Please sign in to comment.