Winand

Untitled

Sep 3rd, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. from PyQt4 import QtGui, QtCore
  2. import sys, socketserver
  3. thd, thd2, thd3 = None, None, None
  4.  
  5. class T(QtCore.QThread):
  6.     def __init__(self, f):
  7.         super().__init__()
  8.         self.f = f
  9.     def run(self):
  10.         print("running", self.f)
  11.         self.f()
  12.  
  13. def thd_fin():
  14.     print("Fin.")
  15.    
  16. def thd_fin3():
  17.     print("Fin3.")
  18.    
  19. class TCPServer(socketserver.TCPServer):
  20.     allow_reuse_address = True
  21. class Handler(socketserver.BaseRequestHandler):
  22.     def handle(self):
  23.         global thd3
  24.         thd3 = T(lambda: None)
  25.         thd3.finished.connect(thd_fin3)
  26.         thd3.start()
  27.  
  28. class Form(QtGui.QWidget):
  29.     def __init__(self):
  30.         super().__init__()
  31.         global thd, thd2
  32.         thd = T(lambda: None)
  33.         thd.finished.connect(thd_fin)
  34.         thd.start()
  35.        
  36.         self.server = TCPServer(("localhost", 50002), Handler)
  37.         global thd2
  38.         thd2 = T(self.server.serve_forever)
  39.         thd2.start()
  40.  
  41. app = QtGui.QApplication(sys.argv)
  42. form = Form()
  43. form.show()
  44. app.exec()
Advertisement
Add Comment
Please, Sign In to add comment