I want to run a python while-loop for x amount of time (2 seconds) and then stop:
from PyQt6 import QtCore
def loop():
stop = False
def stop_loop():
nonlocal stop
stop = True
print('STOPPING LOOP')
timer = QtCore.QTimer()
timer.setSingleShot(True)
timer.setInterval(2000)
timer.timeout.connect(stop_loop)
timer.start()
counter = 0
while 1:
counter += 1
print(counter)
if stop:
break
app = QtCore.QCoreApplication([])
loop()
app.exec_()
But the loop keeps running infinitely and never stops.