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.addDirectory( db, inputDir )
The callback calls 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.
Makes sense -
slicer.app.processEvents() should be used very carefully and only when absolutely needed.
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).