I am trying to pause QThread and resume it.
So, I have an RFID reader loop in QThread, and I want to pause an infinite loop when the reader receives an RFID code. After that, a db check occurs. At the end of the check, I want to resume RFID reading to get other codes.
MVCE:
def main():
global Thread
app = QtGui.QApplication(sys.argv)
main = Main()
Thread = RFID_Thread()
Thread.rfid_event.connect(Main().on_event)
Thread.start()
sys.exit(app.exec_())
class Main(object):
def __init__(self):
self.accueil = MainWindow(self)
self.access = AccessWindow()
self.accueil.show()
def on_event(self, data):
class RFID_Thread(QtCore.QThread):
rfid_event = pyqtSignal(str, name='rfid_event')
def run(self):
while 1:
ser = serial.Serial(port=Serial_Port, baudrate=Serial_Baudrate)
a = ser.read(19).encode('hex')
ser.close()
if len(a) <> 0:
Code = a[14:]
self.rfid_event.emit(Code)
time.sleep(2)
if __name__=='__main__':
main()
the code cannot be reproduced because you need an RFID reader, but we can simulate it with these two lines instead of opening the serial port and reading the data from it:
a = "**************e20030654408021520403f4b"
time.sleep(4)
I tried to use the status variable, but it does not work.
source
share