File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
3
3
import logging
4
- import multiprocessing
5
4
from builtins import dict , map
6
5
from functools import partial
7
6
from itertools import product
7
+ from multiprocessing import Pool
8
8
from typing import List , Set , Union
9
9
10
10
import pandas as pd
@@ -149,14 +149,11 @@ def extract_knockout_results(result_iter):
149
149
gene = _gene_deletion_worker , reaction = _reaction_deletion_worker
150
150
)[entity ]
151
151
chunk_size = len (args ) // processes
152
- pool = multiprocessing .Pool (
153
- processes , initializer = _init_worker , initargs = (model ,)
154
- )
155
- results = extract_knockout_results (
156
- pool .imap_unordered (worker , args , chunksize = chunk_size )
157
- )
158
- pool .close ()
159
- pool .join ()
152
+
153
+ with Pool (processes , initializer = _init_worker , initargs = (model ,)) as pool :
154
+ results = extract_knockout_results (
155
+ pool .imap_unordered (worker , args , chunksize = chunk_size )
156
+ )
160
157
else :
161
158
worker = dict (gene = _gene_deletion , reaction = _reaction_deletion )[entity ]
162
159
results = extract_knockout_results (map (partial (worker , model ), args ))
You can’t perform that action at this time.
0 commit comments