aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/QtAsyncio/events.py
Commit message (Collapse)AuthorAgeFilesLines
* QtAsyncio: Brush up code/add type hintsFriedemann Kleint2025-07-071-35/+46
| | | | | | | Initial-patch-by: Christian Tismer <tismer@stackless.com> Task-number: PYSIDE-769 Change-Id: I7b89d4dea9024b1b926d320a2464821eca5af748 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* qtasyncio: fix f-string quotationCristián Maureira-Fredes2025-04-071-2/+2
| | | | | | | | | | | Considering we still support old Python versions, we cannot have the same quotation mark for f-string and for variables within the f-string. Fixes: PYSIDE-3068 Pick-to: 6.8 6.9 6.9.0 Change-Id: Ie9f1ed91f1a1965631bc71f35600780bb4f00603 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* QtAsyncio: Improve logging when an Exception occurs in a taskLoan Guilbaud2025-03-041-1/+3
| | | | | | | | | | When an exception occurs in a task, the logging is not helpful since it prints out nothing specific about the error that occurred. Catching the traceback and printing it out with the task in which it happened brings a lot of details to resolve the exception faster. Task-number: PYSIDE-3001 Pick-to: 6.8 Change-Id: If199da28a37406779ac5bec178fe756d1757b08c Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Add clarifying commentsAdrian Herrmann2024-07-191-0/+4
| | | | | | | | | | | Add a few more clarifying comments regarding to previous bug fixes or non-obvious variable usages. Pick-to: 6.7 Task-number: PYSIDE-2644 Task-number: PYSIDE-769 Change-Id: Ic4db10510e1adf8141efa83d727f519547d67b24 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* QtAsyncio: Add messages to NotImplementedErrorsAdrian Herrmann2024-07-081-29/+33
| | | | | | | | | | | | Add explanatory messages to NotImplementedError exceptions for less confusing debugging. Pick-to: 6.7 Task-number: PYSIDE-769 Task-number: PYSIDE-2565 Change-Id: Id27afec471668fa2e47a6895ef6f9d8dc5842dee Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
* QtAsyncio: Use modern typing syntaxAdrian Herrmann2024-06-281-52/+47
| | | | | | | | | | | We can already use the modern typing syntax introduced with Python 3.10 in 3.9 via future statement definitions, even before we raise the minimum Python version to 3.10. Task-number: PYSIDE-769 Task-number: PYSIDE-2786 Change-Id: I560d0c25f3503217f920906a5b26193282b0247b Reviewed-by: Christian Tismer <tismer@stackless.com>
* QtAsyncio: Remove application arg from loop policyAdrian Herrmann2024-06-271-7/+1
| | | | | | | | | | | | | Remove the optional application argument from the constructor of QAsyncioEventLoopPolicy, as it is unnecessary. If a QCoreApplication or other type of qApp was created outside of QtAsyncio, it will always be retrieved by QCoreApplication.instance(), and therefore passing it as an argument makes little sense. Task-number: PYSIDE-769 Change-Id: Iac7a913a1c9d6ebbb0984fe11f8b5cda955baab1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
* Python-3.10: Allow the new syntax for Python 3.9Christian Tismer2024-06-201-0/+1
| | | | | | | | Add a future statement to all Python source files. Task-number: PYSIDE-2786 Change-Id: Icd6688c7795a9e16fdcaa829686d57792df27690 Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io>
* QtAsyncio: Clarify usage of singleShot w/o contextAdrian Herrmann2024-06-181-1/+4
| | | | | | | | | | | The singleShot overload that accepts a context argument was used inside the do() method of the QAsyncioExecutorWrapper class, but this usage was unnecessary and adds confusion. Task-number: PYSIDE-769 Change-Id: Idcdd99eda6ae3bfd11ec50b9a42ff15ade005cc9 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
* QtAsyncio: Improve documentation (part 3)Adrian Herrmann2024-05-301-5/+14
| | | | | | | | | | Improve the inline documentation of QtAsyncio with more comprehensive comments. Pick-to: 6.7 Task-number: PYSIDE-769 Change-Id: Ia25bab88de3cb66178ced15fe3b2a4d35e9c09a0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Improve documentation (part 1)Adrian Herrmann2024-05-101-3/+110
| | | | | | | | | | Improve the inline documentation of QtAsyncio with more comprehensive comments. Pick-to: 6.7 Task-number: PYSIDE-769 Change-Id: I3828dea94f770a69e8d0390fd803b923ba932fc2 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Round handle timeoutsAdrian Herrmann2024-04-221-1/+2
| | | | | | | | | | | | Handle timeouts should be rounded up or down instead of only up as happens with a plain int() call. Otherwise, a timeout of e.g. 0.9 would be handled as 0, where 1 would be more appropriate. Pick-to: 6.7 Task-number: PYSIDE-2644 Task-number: PYSIDE-769 Change-Id: I19585010c3e007afb6ae83750e4b6ffc9beb5961 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* QtAsyncio: Improve handling of outside terminationAdrian Herrmann2024-03-151-8/+5
| | | | | | | | | | | | | | Improve how QtAsyncio handles when the QCoreApplication is quit from outside, e.g., when pressing the close button. This will prevent scenarios where asyncio runs the BaseEventLoop destructor after the Qt application had already been shut down, resulting in RuntimeError. In addition, this removes some unnecessary RuntimeError raises related to a closed event loop. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I52553eed271b5fb5790c09751dd58cc2e52fa174 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* QtAsyncio: Add handle_sigint argument to run()Adrian Herrmann2024-03-071-2/+4
| | | | | | | | | | | | An argument handle_sigint determines whether QtAsyncio should handle SIGINT (Ctrl+C) and shut down the event loop when it is received. The default is False. This can be set to True if you want QtAsyncio to take care of handling SIGINT instead of your program. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: Ie4364025448405f36158a8e997d90ae143961ba8 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* QtAsyncio: Fix missing attribute on WindowsAdrian Herrmann2024-02-121-2/+2
| | | | | | | | | | | | The deprecated functions get_child_watcher() and set_child_watcher() of QAsyncioEventLoopPolicy have asyncio.AbstractChildWatcher in their signatures, but this type does not exist on Windows. Use typing forward references to fix this. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I950e6294a247959875f39bd5e7706082cd4f3a0e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Introduce quit_qapp argumentAdrian Herrmann2024-01-301-5/+12
| | | | | | | | | | | | | | | | A new optional argument quit_qapp can be passed to QtAsyncio.run() to configure whether the QCoreApplication at the core of QtAsyncio should be shut down when asyncio finishes. A special case where one would want to disable this is test suites that want to reuse a single QCoreApplication instance across all unit tests, which would fail if this instance is shut down every time. Pick-to: 6.6 Fixes: PYSIDE-2575 Task-number: PYSIDE-769 Change-Id: I49cd0a50311fb30cc50df9b7f6a6d73fe8c58613 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Fix for Python 3.12Adrian Herrmann2024-01-071-3/+18
| | | | | | | | | | | The shutdown_default_executor function was updated with 3.12 to include an optional timeout parameter. Update the function to handle this timeout parameter. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I48b94d640e9940dee84097010fdf1505c82855af Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* QtAsyncio: Implement missing functions for policyAdrian Herrmann2024-01-061-1/+8
| | | | | | | | | | | | Add implementations in QAsyncioEventLoopPolicy for get_child_watcher() and set_child_watcher(). Child watchers are deprecated since 3.12 so we don't need to bother with their logic, we just don't want the linter warning. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I5178e9f6e8d5915741ed3cb65b3432699cba86d0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: mypy fixesAdrian Herrmann2024-01-051-12/+12
| | | | | | | | | Just a few minor mypy fixes. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I4d67270c779606ea2f352a3fddd82941c9118bec Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Catch keyboard interruptsAdrian Herrmann2023-12-191-0/+3
| | | | | | | | | | | | | Catch keyboard interrupts by catching the SIGINT signal and handling it with the default handler. Register the handler with the QAsyncioEventLoopPolicy so that this is always done when using QtAsyncio. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I7b35367a50ab03eb014faabf6b6a3b21a6a3cd6c Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Implement call_soon_threadsafe()Adrian Herrmann2023-12-141-19/+42
| | | | | | | | | | | | | | | Using the QTimer.singleShot(msec, context, functor) overload in QAsyncioHandle already turned call_soon() threadsafe, as that allowed callbacks to be scheduled from other threads. In order to follow the API and distinguish call_soon() and call_soon_threadsafe(), the former is reverted to using the old overload without the context argument, while the latter keeps the new overload. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: Ib2591f994d082b46fe4ec747e590e4d8eb6ff24e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* QtAsyncio: Add wrapper for calls in executorAdrian Herrmann2023-11-241-7/+41
| | | | | | | | | | | | | | | Executors require a bit of extra work for QtAsyncio, as we can't use naked Python threads, instead we must make sure that the thread created by executor.submit() has an event loop. This is achieved by submitting a small wrapper that attaches a QEventLoop to the executor thread, and then creates a singleshot timer to push the actual function for the executor into this new event loop. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I77569d8939d6040ddbe62a99448c6ced2785f27e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* QtAsyncio: Do not raise exception at handle cancelAdrian Herrmann2023-11-241-8/+1
| | | | | | | | | | | Do not raise an exception when cancelling a handle. The exception should be raised later, when retrieving the future's result. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I8243cf16e8be5afe167d69313054e97e9aafc75c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
* QtAsyncio: Don't schedule events when quitting appAdrian Herrmann2023-10-111-1/+12
| | | | | | | | | | | Do not schedule events from asyncio when the app is quit from outside the event loop, as this would cause events to be enqueued after the event loop was destroyed. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: Ib9ff3949653783e4a9484a8a28f1c0010dcff33f Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* QtAsyncio: Add queues testAdrian Herrmann2023-09-121-2/+6
| | | | | | | | | | Add a test for the asyncio queue for consumer/producer scenarios. Additionally, fix a few bugs exposed by this test through the increased code coverage. Task-number: PYSIDE-769 Change-Id: I18e3be6d059b758868a7598b58704db216bcdcc8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Fix time unitAdrian Herrmann2023-09-121-7/+7
| | | | | | | | | loop.time() needs to return the time in seconds as a float, not in milliseconds as an int. Task-number: PYSIDE-769 Change-Id: Iac123132b49d3954abda8545d0830f1837a27c48 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Implement custom asyncio event loop based on QtAdrian Herrmann2023-07-271-0/+512
asyncio is an established library for Python applications with concurrency and asynchronous I/O, and the de facto standard that multiple other async frameworks build upon. Like Qt, it is based on an event loop, so to this end, it offers an extensive API to implement custom event loops that applications using asyncio can then leverage. Task-number: PYSIDE-769 Change-Id: I3daf5d631e2fa0d44fd8c3c272ac5cce96f58653 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>