# Multiprocessing is not working when PyQt widgets , DataProbe and DicomLib are used.

**URL:** <https://discourse.slicer.org/t/multiprocessing-is-not-working-when-pyqt-widgets-dataprobe-and-dicomlib-are-used/23595>\
**Category:** Support\
**Created:** [May 26, 2022, 2:40pm UTC](https://discourse.slicer.org/t/multiprocessing-is-not-working-when-pyqt-widgets-dataprobe-and-dicomlib-are-used/23595 "2022-05-26T14:40:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roopesh](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@roopesh](https://discourse.slicer.org/u/roopesh)\
**Post date:** [May 26, 2022, 2:40pm UTC](https://discourse.slicer.org/t/multiprocessing-is-not-working-when-pyqt-widgets-dataprobe-and-dicomlib-are-used/23595/1 "2022-05-26T14:40:37Z")

</div>

I am running an algorithm in a python script using command line with --python-script command, which has a custom button created in slicer UI, when I trigger this button , algorithm will start, which is using multiprocessing and creating spawn type context object and runs several processes. When I did that I am getting error as below.

 ![Screenshot from 2022-05-26 16-40-21](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/d/4dbc8e51422b4e604441d5182882b6a7042e0c50.png)

When I removed the places wherever I am using QtWidgets, DataProbe and DicomLib then the python script is running multiprocessing and algorithm successfully. These libraries are required for my complete functionality, so I can’t remove them. Please help me here.

---

<div class="post-metadata">

**Author:** ![roopesh](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@roopesh](https://discourse.slicer.org/u/roopesh)\
**Post date:** [May 31, 2022, 3:58am UTC](https://discourse.slicer.org/t/multiprocessing-is-not-working-when-pyqt-widgets-dataprobe-and-dicomlib-are-used/23595/2 "2022-05-31T03:58:17Z")

</div>

@lassoan Please help me out here, its kinda urgent.

---

<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:** [May 31, 2022, 4:08am UTC](https://discourse.slicer.org/t/multiprocessing-is-not-working-when-pyqt-widgets-dataprobe-and-dicomlib-are-used/23595/3 "2022-05-31T04:08:54Z")

</div>

Most objects are only usable on a single thread. Therefore, you usually cannot simply run the same code in a processing thread that works on the main thread.

You can only run processing in the worker threads and you must not access GUI widgets and application objects. See [GitHub - pieper/SlicerParallelProcessing: Slicer modules for running subprocesses to operate on data in parallel](https://github.com/pieper/SlicerParallelProcessing) extension for examples of how you can implement parallel processing in Python in Slicer.
