def stop(self, force=False):
if self.process is not None:
if not force:
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle('Confirm process termination')
msg.setText(
'This will terminate the running process. Are you sure '
'you want to do this?')
msg.setInformativeText(
'Interrupting the process may leave partly '
'created files that cannot be used for '
'further analysis.')
msg.addButton('Stop process', QMessageBox.YesRole)
cancel_button = msg.addButton('Cancel', QMessageBox.NoRole)
msg.setDefaultButton(cancel_button)
msg.exec_()
if msg.clickedButton() == cancel_button:
# Continue to run
return
self._interrupted = True
# Terminate child processes as well
pid = int(self.process.pid())
if sys.platform == 'win32' and pid != 0:
# The returned value is not a PID but a pointer
lp = ctypes.cast(pid, LPWinProcInfo)
pid = lp.contents.dwProcessID
if pid != 0:
process = psutil.Process(pid)
children = process.children(recursive=True)
for proc in children:
proc.terminate()
gone, alive = psutil.wait_procs(children, timeout=3)
for proc in alive:
proc.kill()
self.process.terminate()
self.process = None
评论列表
文章目录