pieper / SlicerParallelProcessing

Slicer modules for running subprocesses to operate on data in parallel
Other
11 stars 5 forks source link

How to cancel a process launched ? #12

Closed tony-wolff closed 1 year ago

tony-wolff commented 1 year ago

I launched a registration with this extension. I have a button cancel, that kills the registration process obtained like this : self.regProcess = RegistrationProcess(scriptPath, fixed_image, moving_image, input) with registrationProcess is a subclass of Process. The problem is I believe it does not correctly finish, since my ram and processor is used quite much. How can I properly cancel a parallel process ?

pieper commented 1 year ago

The Process python class is a subclass of QProcess, so calling the kill() method should work.

https://doc.qt.io/qt-5/qprocess.html#kill

tony-wolff commented 1 year ago

That's what I'm doing whit this for process in self.process_logic.processLists["Running"]: process.kill() for process in self.process_logic.processLists["Completed"]: process.kill() for process in self.process_logic.processLists["Failed"]: process.kill() for process in self.process_logic.processLists["Pending"]: process.kill() However, when I use the top command in my terminal, I still see the process running at 300% cpu power

tony-wolff commented 1 year ago

It seems that the process created another process, with almost the same PID, and the pattern is that the child gets +10 on the parent PID. So I os.kill this pid and then I used self.regProcess.kill() to finish it, and it works.