Skip to content

Commit ac1a3d0

Browse files
committed
CU-8699qg2tg: Force spawn-based multirpocessing (#38)
1 parent d89038d commit ac1a3d0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

medcat-v2/medcat/cat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
class CAT(AbstractSerialisable):
4242
"""This is a collection of serialisable model parts.
4343
"""
44+
FORCE_SPAWN_MP = True
4445

4546
def __init__(self,
4647
cdb: CDB,
@@ -381,6 +382,13 @@ def _multiprocess(
381382
batch_iter: Iterator[list[tuple[str, str, bool]]]
382383
) -> Iterator[tuple[str, Union[dict, Entities, OnlyCUIEntities]]]:
383384
external_processes = n_process - 1
385+
if self.FORCE_SPAWN_MP:
386+
import multiprocessing as mp
387+
logger.info(
388+
"Forcing multiprocessing start method to 'spawn' "
389+
"due to known compatibility issues with 'fork' and "
390+
"libraries using threads or native extensions.")
391+
mp.set_start_method("spawn", force=True)
384392
with ProcessPoolExecutor(max_workers=external_processes) as executor:
385393
yield from self._mp_one_batch_per_process(
386394
executor, batch_iter, external_processes)

0 commit comments

Comments
 (0)