I develop app in Python 3.8 with PyQt5.
I need to run and able to kill a separate process from the PyQT Form. When I use process.start and then process.kill it kills the process.
But when I use process.startDetached()
then process.kill()
doesn't work.
Below is an example:
from form import Ui_MainWindow
from PyQt5 import QtWidgets
class myapp(QtWidgets.QMainWindow):
def __init__(self):
super(myapp, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.process = QProcess(self)
self.ui.pushButton.clicked.connect(self.btnClicked)
self.ui.pushButton_2.clicked.connect(self.process.kill)
def btnClicked(self):
runstr = 'ping'
args = ['localhost','-t']
self.process.startDetached(runstr, args)
app = QtWidgets.QApplication([])
application = myapp()
application.show()
sys.exit(app.exec())
Could you advise the way how to kill a process in detached mode.