aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/QtAsyncio
Commit message (Collapse)AuthorAgeFilesLines
* QtAsyncio: Add clarifying commentsAdrian Herrmann2024-07-192-6/+18
| | | | | | | | | | | 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: Don't cancel handleAdrian Herrmann2024-07-161-2/+1
| | | | | | | | | | | | | | | It is not necessary to cancel a task's handle when cancelling said task, as the step function already handles the cancellation. Furthermore, cancelling the handle can cause issues with TaskGroups if an exception is raised inside the TaskGroup's context, where the tasks inside the group are not allowed to properly cancel and thus block the program. Pick-to: 6.7 Task-number: PYSIDE-769 Fixes: PYSIDE-2799 Change-Id: I1ab782380ffbe8c1ec40aba22b9ed2ebdcb1498f Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Add cancel count and uncancelAdrian Herrmann2024-07-161-9/+18
| | | | | | | | | | | | | | | | Implement the QAsyncioTask.uncancel() function and the associated cancel count. Note to reader: Unlike what the name suggests, the uncancel() function on its own does not undo a task cancellation. This must be performed by consuming the CancelledError exception, at which point uncancel() serves to remove the cancellation state. Pick-to: 6.7 Task-number: PYSIDE-769 Fixes: PYSIDE-2790 Change-Id: I4e817e1dd3f49179855432d20ed2f043090fd8f1 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@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-284-87/+81
| | | | | | | | | | | 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: Properly document run() argsAdrian Herrmann2024-06-271-1/+19
| | | | | | | | | Properly document the arguments to QtAsyncio.run() with a docstring instead of leaving it only to the module rst. Task-number: PYSIDE-769 Change-Id: Ia4d63b3cdf81d052203a2752ed3ca6cb0b40f814 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* QtAsyncio: Remove application arg from loop policyAdrian Herrmann2024-06-272-8/+7
| | | | | | | | | | | | | 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-204-0/+4
| | | | | | | | 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 2)Adrian Herrmann2024-05-103-8/+43
| | | | | | | | | | Improve the inline documentation of QtAsyncio with more comprehensive comments. Pick-to: 6.7 Task-number: PYSIDE-769 Change-Id: I7306da43d8f1f350dae188f5346cdec8f60a7a06 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: Improve readability of _stepAdrian Herrmann2024-04-241-10/+9
| | | | | | | | | | Improve the readability of the QAsyncioTask._step function; avoid nested try/except blocks. Pick-to: 6.7 Task-number: PYSIDE-769 Change-Id: Ibb82c50cf93b084b30dd2a5abcc0197ae25802e0 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: Fix tasks with loop not cancellingAdrian Herrmann2024-04-221-0/+11
| | | | | | | | | | | | | | | If a task was cancelled, then a new future created from this task should be cancelled as well. Otherwise, in some scenarios like a loop inside the task and with bad timing, if the new future is not cancelled, the task would continue running in this loop despite having been cancelled. This bad timing can occur especially if the first future finishes very quickly. Pick-to: 6.7 Fixes: PYSIDE-2644 Task-number: PYSIDE-769 Change-Id: Icfff6e4ad5da565f50e3d89fbf85d1fecbf93650 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: Reset loop policy after QtAsyncio.run()Adrian Herrmann2024-03-111-2/+13
| | | | | | | | | | | | | | When running QtAsyncio.run(), the global asyncio event loop policy is set. Currently, the policy setting is kept to QtAsyncio's policy even after QtAsyncio.run() returns, which can lead to unexpected behavior (e.g., if executing asyncio.run() afterwards expecting the default event loop to be used). Reset the event loop policy to the default one after returning from QtAsyncio.run() to mitigate this. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: Ifd31c0924317ba09c53ded165c9a5d6f1e2dc808 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* QtAsyncio: Add handle_sigint argument to run()Adrian Herrmann2024-03-072-3/+7
| | | | | | | | | | | | 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 return value of run()Adrian Herrmann2024-03-071-2/+2
| | | | | | | | | | If QtAsyncio.run() executes asyncio.run(), then its return value should be passed on. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: Ic36e3bfd0f15b0697e310af3d9eb4ff6998ffce0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@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-302-7/+15
| | | | | | | | | | | | | | | | 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: Make tasks awaitableAdrian Herrmann2024-01-072-9/+1
| | | | | | | | | | | | Tasks are supposed to be awaitable objects. Fix a leftover from an old misunderstanding of tasks vs futures very early in the development process. Pick-to: 6.6 Fixes: PYSIDE-2561 Task-number: PYSIDE-769 Change-Id: I916d6e235c5e67ea0d03f1df3b1bf8dfd8cb9c83 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Fix cancelling waiting tasksAdrian Herrmann2024-01-072-8/+15
| | | | | | | | | | A task that is awaiting a future must also cancel this future in order for the cancellation to be successful. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I22a9132fc8506e7a007fe625bc9217f0760bdc6b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@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: Fix QtAsyncio.run()Adrian Herrmann2024-01-051-5/+25
| | | | | | | | | | | | Programs started with QtAsyncio.run() were not terminating correctly in some scenarios. Add a keep_running argument to distinguish cases where the program is supposed to end after a coroutine finished and those where we want to keep the event loop active. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I87857bac7c55aa68c0e273fb0ecf94848d8c2bae 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: Add QtAsyncio.run() functionAdrian Herrmann2023-12-201-0/+12
| | | | | | | | | | | | | | | | | Add a QtAsyncio.run() function as the new recommended method to launch QtAsyncio programs. This abstracts the event loop policy and reduces the API to one single call. Additionally, this will allow to transparently replace the event loop policy with a loop factory when event loop policies are removed in Python 3.15 following their deprecation in 3.12. More information: https://discuss.python.org/t/removing-the-asyncio-policy-system-asyncio-set-event-loop-policy-in-python-3-15/37553 Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I59d7eeb81debe92315351995f041caead4f51d8b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* QtAsyncio: Catch keyboard interruptsAdrian Herrmann2023-12-193-3/+6
| | | | | | | | | | | | | 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-243-11/+5
| | | | | | | | | | | 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: Handle exceptions properly in task stepAdrian Herrmann2023-11-242-11/+14
| | | | | | | | | | | Refactor the task step function to handle exceptions properly, as the self._coro.throw() code path was not usually reachable. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I31d50f700857a47bf1df5f0f02fb2fa313c1c045 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@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 _cancel_message to future + taskAdrian Herrmann2023-10-022-0/+3
| | | | | | | | | | This field is assumed by asyncio.gather() to exist in task or future classes despite being undocumented. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: Ieab6f216db95e40bd02625fb9cff69be0ebccd50 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Do not stop loop at task completionAdrian Herrmann2023-10-021-1/+0
| | | | | | | | | | | An erroneous self._loop.stop() has sneaked into the end of QAsyncioTask._step, causing the event loop to stop prematurely in some scenarios. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: If155e43f81675c660766c00e766e8a8f3bbe8b38 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Miscellaneous improvements to TaskAdrian Herrmann2023-09-291-5/+9
| | | | | | | | | | | - Use asyncio._register_task() and asyncio._unregister_task() as demanded by the API (extending asyncio, Task lifetime support) - Add some comments and a missing return type in signature Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I3ffdf0dc5f7b127c0dd9f2fb63eecb057d123744 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Fix signature of cancel for future/taskAdrian Herrmann2023-09-192-3/+7
| | | | | | | | | | QAsyncioFuture.cancel() and QAsyncioTask.cancel() should both return a bool. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I2b507ad5c44ba9478bdf8a53c0cd5464028d3384 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Use asyncio._enter_task and _leave_taskAdrian Herrmann2023-09-191-0/+5
| | | | | | | | | | Wrap a QAsyncioTask's step execution with calls to asyncio._enter_task() and asyncio._leave_task() so that asyncio.current_task() will work. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I7235c9ab2b8d68b0059b82a366909dc25ea6d60f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QtAsyncio: Add queues testAdrian Herrmann2023-09-123-6/+11
| | | | | | | | | | 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-274-0/+769
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>