Python exits abnormally when using spawn method to create a new process in multiprocessing on Unix

On Unix, mutiprocessing works well with default creating new process method (fork). However, if I set the creating method as spawn, python exits abnormally. I could not get the reason why python exits abnormally. Here is my simple testing code:

def test_mp():
    num_processes = 3
    print("chengs++: mp start a new process with method: ", get_start_method())
    set_start_method('spawn', force=True)
    print("chengs++: mp start a new process with method after resetting to spawn: ", get_start_method())
    with Pool(num_processes) as pool:
        results = pool.starmap(
                [2] * num_processes,
                [1] * num_processes,

def doubler(number, r):
    result = number * 2 + r
    return result

If you have any clue, please let me know. Thanks in advance.

You may need to use recent Slicer Preview Release for this to work. But there is a good chance that you can only use the default multiprocessing method because Slicer uses an embedded Python interpreter, which may manage threading differently than what multiprocessing expects.

There are many different multiprocessing options in Slicer - as they have been discussed on this forum before. Let us know if you don’t find those discussions or you have remaining questions.

Thanks, Lassoan.

I got latest preview release version. It did not work.

I search the forum. No issue with the spawn method in mutiprocessing.

1 Like