|
100 | 100 | from ._common import with_logger # noqa |
101 | 101 |
|
102 | 102 |
|
| 103 | +_AllEvents = QtCore.QEventLoop.ProcessEventsFlags(0x00) |
| 104 | + |
| 105 | + |
103 | 106 | @with_logger |
104 | 107 | class _QThreadWorker(QtCore.QThread): |
105 | 108 | """ |
@@ -234,7 +237,7 @@ def __exit__(self, *args): |
234 | 237 |
|
235 | 238 | def _format_handle(handle: asyncio.Handle): |
236 | 239 | cb = getattr(handle, "_callback", None) |
237 | | - if isinstance(getattr(cb, '__self__', None), asyncio.tasks.Task): |
| 240 | + if isinstance(getattr(cb, "__self__", None), asyncio.tasks.Task): |
238 | 241 | return repr(cb.__self__) |
239 | 242 | return str(handle) |
240 | 243 |
|
@@ -292,7 +295,11 @@ def timerEvent(self, event): # noqa: N802 |
292 | 295 | handle._run() |
293 | 296 | dt = time.time() - t0 |
294 | 297 | if dt >= loop.slow_callback_duration: |
295 | | - self._logger.warning('Executing %s took %.3f seconds', _format_handle(handle), dt) |
| 298 | + self._logger.warning( |
| 299 | + "Executing %s took %.3f seconds", |
| 300 | + _format_handle(handle), |
| 301 | + dt, |
| 302 | + ) |
296 | 303 | finally: |
297 | 304 | loop._current_handle = None |
298 | 305 | else: |
@@ -338,7 +345,7 @@ class _QEventLoop: |
338 | 345 | ... await asyncio.sleep(.1) |
339 | 346 | >>> |
340 | 347 | >>> asyncio.run(xplusy(2, 2), loop_factory=lambda:QEventLoop(app)) |
341 | | - |
| 348 | +
|
342 | 349 | If the event loop shall be used with an existing and already running QApplication |
343 | 350 | it must be specified in the constructor via already_running=True |
344 | 351 | In this case the user is responsible for loop cleanup with stop() and close() |
@@ -420,7 +427,9 @@ def stop(*args): |
420 | 427 | self.run_forever() |
421 | 428 | finally: |
422 | 429 | future.remove_done_callback(stop) |
423 | | - self.__app.processEvents() # run loop one last time to process all the events |
| 430 | + self.__app.eventDispatcher().processEvents( |
| 431 | + _AllEvents |
| 432 | + ) # run loop one last time to process all the events |
424 | 433 | if not future.done(): |
425 | 434 | raise RuntimeError("Event loop stopped before Future completed.") |
426 | 435 |
|
|
0 commit comments