# Concurrent calls to slicer app processEvents() crashing slicer

**URL:** <https://discourse.slicer.org/t/concurrent-calls-to-slicer-app-processevents-crashing-slicer/9970>\
**Category:** Development\
**Created:** [January 27, 2020, 3:49pm UTC](https://discourse.slicer.org/t/concurrent-calls-to-slicer-app-processevents-crashing-slicer/9970 "2020-01-27T15:49:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fbordignon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fbordignon/32/5269_2.png) [@fbordignon](https://discourse.slicer.org/u/fbordignon)\
**Post date:** [January 27, 2020, 3:49pm UTC](https://discourse.slicer.org/t/concurrent-calls-to-slicer-app-processevents-crashing-slicer/9970/1 "2020-01-27T15:49:39Z")

</div>

Slicer is randomly crashing if I register a callback to the dicom indexer and make my callback call slicer.app.processEvents()

```
self.indexer = ctk.ctkDICOMIndexer()
self.indexer.connect("progress(int)", updateProgress)
self.indexer.addDirectory( db, inputDir )

```

The callback calls processEvents:

```
def updateProgress():
    ...
    slicer.app.processEvents()

```

I suspect that the callback is being called concurrently and crashing slicer by calling processEvents concurrently. If I use a mutex for preventing the call to processEvents by more than one thread, it works.

---

<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 27, 2020, 7:36pm UTC](https://discourse.slicer.org/t/concurrent-calls-to-slicer-app-processevents-crashing-slicer/9970/2 "2020-01-27T19:36:19Z")

</div>

Makes sense - `slicer.app.processEvents()` should be used very carefully and only when absolutely needed.

---

<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:** [January 27, 2020, 7:53pm UTC](https://discourse.slicer.org/t/concurrent-calls-to-slicer-app-processevents-crashing-slicer/9970/3 "2020-01-27T19:53:08Z")

</div>

If you call processEvents() inside an event handler, you may get into infinite recursion (and there might be other issues), so don’t do it.

Since ctkDICOMIndexer can run in non-blocking mode (set `indexer.backgroundImportEnabled=True`), it is not necessary to call `slicer.app.processEvents()` at all. If the main thread is not blocked then all events are processed automatically. You can use the application while the import in the background is running; or show a popup window to block the user from wandering away.

You may also use the DICOM module’s indexer, which shows the progress in the DICOM browser and does not block the application at all (as it is done in this [test/example](https://github.com/Slicer/Slicer/blob/master/Applications/SlicerApp/Testing/Python/RSNAVisTutorial.py#L196-L200)).
