I am trying to create a program to easily handle IT requests, and I have created a program to test if a PC on my network is active from a list.
To do this, I wrote the following code:
self.btn_Ping.clicked.connect(self.ping)
def ping(self):
hostname = self.listWidget.currentItem().text()
if hostname:
os.system("ping " + hostname + " -t")
When I run it my main program freezes and I can't do anything until I close the ping command window. What can I do about this? Is there any other command I can use to try to ping a machine without making my main program freeze?
pingcommand with the-n 1argument, so that only one attempt is made to contact the remote machine. The-toption you're using is supposed to "Ping the specified host until stopped." as per the documentation, so it's doing exactly what you asked of it.os.system. Usesubprocess.call(["ping", hostname, "-t"])instead.os.systemis wronger. It waits for the command to complete. Don't useos.popeninstead.