def test_pyqt5_schedule_periodic_cancel(self, app): scheduler = QtScheduler(QtCore) gate = threading.Semaphore(0) period = 0.05 counter = 3 def action(state): nonlocal counter if state: counter -= 1 return state - 1 disp = scheduler.schedule_periodic(period, action, counter) def dispose(): disp.dispose() QtCore.QTimer.singleShot(100, dispose) def done(): app.quit() gate.release() QtCore.QTimer.singleShot(300, done) app.exec_() gate.acquire() assert 0 < counter < 3
def test_pyside2_schedule_action_periodic(self, app): scheduler = QtScheduler(QtCore) gate = threading.Semaphore(0) period = 0.050 counter = 3 def action(state): nonlocal counter if state: counter -= 1 return state - 1 scheduler.schedule_periodic(period, action, counter) def done(): app.quit() gate.release() QtCore.QTimer.singleShot(300, done) app.exec_() gate.acquire() assert counter == 0