Slicers hangs while running a scripted module

Hi,
could you please suggest the best way to avoid any slicer hang.
The python scripted module I wrote runs succesfully but in between the slicer hangs asking for to wait or force quit. how to avoid?

The module purpose is to run 300 images and get the segmentation automatically using bratstoolkit and managing the directories it create for 300 images. On top of that I am using 3D Slicer to apply the transform to the segmented region of interest to get it aligned with the original MRI for each of these images and saving the transformed segmentation.

The slicer windows pop up telling to force quit or wait? how to get rid of this issue? I did wait every time and then it runs fine but how to avoid this issue?

Also i am using the nightly build version of slicer not the stable release.

Thank you

regards,
Saima

If Slicer is busy running your long script then it is normal that it is not responsive. Quit if you want to abort your processing, but otherwise just wait for your operations to complete. If you want to be able to have some interaction (visualize something, process button click events, etc.) then you can call slicer.app.processEvents() time to time.

In Ubuntu and the like this is due to the operating system checking if the application is responsive. You can change the OS parameters driving this check to make it less sensitive (Ubuntu 22.04 too eager).