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

**URL:** <https://discourse.slicer.org/t/python-exits-abnormally-when-using-spawn-method-to-create-a-new-process-in-multiprocessing-on-unix/8929>\
**Category:** Support\
**Created:** [October 28, 2019, 7:54pm UTC](https://discourse.slicer.org/t/python-exits-abnormally-when-using-spawn-method-to-create-a-new-process-in-multiprocessing-on-unix/8929 "2019-10-28T19:54:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guangshan\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/guangshan_chen/32/4832_2.png) [@Guangshan\_Chen](https://discourse.slicer.org/u/Guangshan_Chen)\
**Post date:** [October 28, 2019, 7:54pm UTC](https://discourse.slicer.org/t/python-exits-abnormally-when-using-spawn-method-to-create-a-new-process-in-multiprocessing-on-unix/8929/1 "2019-10-28T19:54:28Z")

</div>

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(
            doubler,
            zip(
                [2] * num_processes,
                [1] * num_processes,
            ),
        )
    print(results)

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

```

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 28, 2019, 9:26pm UTC](https://discourse.slicer.org/t/python-exits-abnormally-when-using-spawn-method-to-create-a-new-process-in-multiprocessing-on-unix/8929/2 "2019-10-28T21:26:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Guangshan\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/guangshan_chen/32/4832_2.png) [@Guangshan\_Chen](https://discourse.slicer.org/u/Guangshan_Chen)\
**Post date:** [October 29, 2019, 3:14pm UTC](https://discourse.slicer.org/t/python-exits-abnormally-when-using-spawn-method-to-create-a-new-process-in-multiprocessing-on-unix/8929/3 "2019-10-29T15:14:31Z")

</div>

Thanks, Lassoan.

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

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