Slicer crashing when using multiprocessing or multi threading

Hi guys,

I am currently working on a voice interface for 3D slicer. I’m implementing it using a scripted module for 3d Slicer where it creates a child process, and then continually listens for words from the child process (by checking a queue). It must then perform a change to the mrml scene using this received word (e.g., selecting the ROI tool; applying a window preset to a selected volume; changing the color lookup table of a volume).

My first issue is that when I start a child process using python multiprocessing, this results in the Slicer application crashing. Is python multiprocessing not supported by Slicer?

Furthermore, I am running into an issue when implementing listening. I have tried using a qt timer to constantly check the queue, but for some reason the behavior is unstable, and the applications crashes when I click something in the tool bar (e.g, change a module, select a different markup). I also tried creating a child thread which constantly checks the word queue, but this creates unstable and delayed behavior (I have seen forum posts saying that Slicer does not support multi threading). Lastly, I tried a solution using signals, but the signal handler has a massive delay (I’m not sure if 3D Slicer supports signals).

Have my approaches been wrong, or maybe there’s an error in the code I’m writing?

Any advice would be greatly appreciated, cheers!


Have a look at how things are done here: GitHub - pieper/SlicerParallelProcessing: Slicer modules for running subprocesses to operate on data in parallel

The QProcess is a very nice abstraction of OS processes and provides a clean set of signals for state changes and also exposes the input, output, and error in a way that you can get signals when it’s valid to read/write, so there’s a clean integration with the event loop and no messy timers required.

Hi Steve,

Thanks a lot for your prompt response! I’ll have a look at the resources you sent through and implement my program accordingly. I’ll keep you guys posted on how things work out.