pingThread.py 623 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. import time
  4. from PyQt5.QtCore import (QThread, pyqtSignal, pyqtSlot)
  5. import ping
  6. from functions import *
  7. import socket
  8. class pingThread(QThread):
  9. pong = pyqtSignal(float)
  10. def __init__(self, ip, timeout = 4):
  11. QThread.__init__(self)
  12. self.ip = ip
  13. self.timeout = timeout
  14. def run(self):
  15. while True:
  16. try:
  17. t = ping.do_one(self.ip, self.timeout)
  18. except (socket.error, UnicodeError) as e:
  19. print(e)
  20. t = None
  21. if t == None:
  22. t = -1
  23. self.pong.emit(t)
  24. time.sleep(1)
  25. def changeIP(self, ip):
  26. self.ip = ip