# How to load volume in the subprocess in python?

**URL:** <https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245>\
**Category:** Development\
**Created:** [January 15, 2023, 8:32am UTC](https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245 "2023-01-15T08:32:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [January 15, 2023, 8:32am UTC](https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245/1 "2023-01-15T08:32:34Z")

</div>

i have tryed to use SlicerParallelProcessing  
SlicerParallelProcessing can’t import slicer.util package

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 15, 2023, 6:19pm UTC](https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245/2 "2023-01-15T18:19:44Z")

</div>

The examples use PythonSlicer, which is just the python interpreter part of Slicer, not the full app. In the examples I use the stdin/stdout of PythonSlicer to pass data back and forth, which fits some processing workflows. It would be possible to use the same process management techniques to run the Slicer app, perhaps with `--no-main-window` and then exchange data using other channels, like tempfiles or the WebServer, but there are no examples of that right now.

> <https://github.com/pieper/SlicerParallelProcessing/blob/master/Processes/Processes.py#L227>

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [January 16, 2023, 1:04am UTC](https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245/3 "2023-01-16T01:04:07Z")

</div>

thank you pieper  
now i run a Slicer main App,and i want to use some feather of Slicer to Run SlicerParallelProcessing , so i need to start a second and third Slicer Sub App to do that. and pass data with stdin/stdout

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 16, 2023, 6:09pm UTC](https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245/4 "2023-01-16T18:09:04Z")

</div>

Unfortunately you can’t communicate with the Slicer app via stdin/stdout, but you can have several instances running at the same time.

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [January 17, 2023, 12:47am UTC](https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245/5 "2023-01-17T00:47:08Z")

</div>

if i want to use some feather of slicer in multi thread or multi process , can i write multithread in C++ function, and invoke the function use python script?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 17, 2023, 10:20pm UTC](https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245/6 "2023-01-17T22:20:30Z")

</div>

If you are building Slicer from source you can add C++ code. We typically use Qt, VTK or ITK for implementing C++ features.

If you want to use a slicer binary, you could compile a separate executable and run it from Slicer and pass data, either with the ParallelProcessing extension or with the Slicer CLI Execution Model (see, for example, [this page](https://www.slicer.org/wiki/Documentation/Nightly/Developers/SlicerExecutionModel)).

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [January 18, 2023, 12:44am UTC](https://discourse.slicer.org/t/how-to-load-volume-in-the-subprocess-in-python/27245/7 "2023-01-18T00:44:23Z")

</div>

thank you very much @pieper
