Running a Module in Parallel


I am currently using a python scripted module to run my vertebra segmentation program. The program uses a for loop to segment multiple fiducial points. This process takes a long time to run and I thought that running in parallel would take a shorter time than iterating through a loop. How can I run my program in parallel using python?

@cpinter @Sunderlandkyl @lassoan

Your most likely route is to call into a c++ library from python.

Python scripted module -> c++ (loadable) module with no GUI -> set flag when finished processing

Another option is to start an independent PythonSlicer process and pass over the data it needs. The SlicerProcess module does this using pickle and stdio, making it pretty efficient. The nice thing is that you get a complete slicer python environment with all the same libraries but independent of mrml and the GUI.

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Does anybody know how to do this?

So I have opened up a scriptedcli module and I have my function that I would like to copy on to there (the onApplybutton function from the slicer scripted module), how do I effectively transfer this code to my scriptedcli module and then run this with my scripted module?

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


I have a local threshold segmentation code in a scripted python module which iterates through fiducial points and runs the local threshold function. Iterating through points takes a while to do and to speed it up, I would like it to run in parallel with a scripted CLI python module. I have set a list of parameters, and I have this line of code:

slicer.cli.runSync(slicer.modules.climodulecode, None, param, True, True)

I am not sure what to do in terms of adding code to the scripted cli module and how to use the parameters from there. I have looked at some examples but I am still a little unclear.


param = {“inputVolume”: masterVolumeNode.GetID(), “MinimumThreshold”: 265, “MaximumThreshold”: 1009, “MinimumDiameterMm”: 9, “Seed”:fidList.getID()}

These are my parameters. Any ideas? @lassoan @pieper

slicer.cli.runSync blocks execution until processing is complete. slicer.cli.runAsync blocks execution until processing is complete., wait_for_completion = False) is not much better either, as Slicer always runs only one CLI at a time (the only advantage is that you can still use Slicer while computation is running in the background). For parallel execution, I would recommend to use @pieper’s SlicerProcesses extension.

Another approach is to keep a single process but use multiple seeds. LocalThreshold effect uses only a single input point, but you could modify it to take all your input points at once.

However, before you would start trying these, the most important thing is to profile your existing implementation. You need to know what line(s) of code take most of the time and focus only on those. There are Python profilers that you can configure or you can measure approximate execution time by adding log messages.