forked from altendky/qtrio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_core.py
More file actions
730 lines (570 loc) · 24.9 KB
/
Copy path_core.py
File metadata and controls
730 lines (570 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
"""The module holding the core features of QTrio.
Attributes:
_reenter_event_type: The event type enumerator for our reenter events.
"""
from __future__ import annotations
import contextlib
import math
import sys
import typing
import typing_extensions
import warnings
import async_generator
import attr
import outcome
import qts
import qts.util
import trio
import trio.abc
import qtrio
import qtrio._qt
if typing.TYPE_CHECKING or "sphinx_autodoc_typehints" in sys.modules:
from qts import QtCore
from qts import QtGui
from qts import QtWidgets
_reenter_event_type: typing.Optional["QtCore.QEvent.Type"] = None
def registered_event_type() -> typing.Optional["QtCore.QEvent.Type"]:
"""Get the registered event type.
Returns:
The type registered with Qt for the reenter event. :obj:`None` if no event type
has been registered yet.
"""
return _reenter_event_type
def register_event_type() -> None:
"""Register a Qt event type for use by Trio to reenter into the Qt event loop.
Raises:
qtrio.EventTypeAlreadyRegisteredError: if an event type has already been
registered.
qtrio.EventTypeRegistrationFailedError: if a type was not able to be
registered.
"""
from qts import QtCore
global _reenter_event_type
if _reenter_event_type is not None:
raise qtrio.EventTypeAlreadyRegisteredError()
event_hint = QtCore.QEvent.registerEventType()
if event_hint == -1:
raise qtrio.EventTypeRegistrationFailedError()
# assign to the global
# TODO: https://bugreports.qt.io/browse/PYSIDE-1347
if qts.is_pyside_5_wrapper: # pragma: no cover
_reenter_event_type = typing.cast(
typing.Callable[[int], QtCore.QEvent.Type], QtCore.QEvent.Type
)(event_hint)
else:
_reenter_event_type = QtCore.QEvent.Type(event_hint)
def register_requested_event_type(requested_value: int | QtCore.QEvent.Type) -> None:
"""Register the requested Qt event type for use by Trio to reenter into the Qt event
loop.
Arguments:
requested_value: The value to ask Qt to use for the event type being registered.
Raises:
qtrio.EventTypeAlreadyRegisteredError: if an event type has already been
registered.
qtrio.EventTypeRegistrationFailedError: if a type was not able to be registered.
qtrio.RequestedEventTypeUnavailableError: if the type returned by Qt does not
match the requested type.
"""
from qts import QtCore
global _reenter_event_type
if _reenter_event_type is not None:
raise qtrio.EventTypeAlreadyRegisteredError()
# TODO: https://bugreports.qt.io/browse/PYSIDE-1468
if qts.is_pyside_5_wrapper: # pragma: no cover
event_hint = typing.cast(
typing.Callable[[int | QtCore.QEvent.Type], int],
QtCore.QEvent.registerEventType,
)(requested_value)
else:
event_hint = QtCore.QEvent.registerEventType(requested_value)
if event_hint == -1:
raise qtrio.EventTypeRegistrationFailedError()
elif event_hint != requested_value:
raise qtrio.RequestedEventTypeUnavailableError(
requested_type=requested_value, returned_type=event_hint
)
# assign to the global
# TODO: https://bugreports.qt.io/browse/PYSIDE-1347
if qts.is_pyside_5_wrapper: # pragma: no cover
_reenter_event_type = typing.cast(
typing.Callable[[int], QtCore.QEvent.Type], QtCore.QEvent.Type
)(event_hint)
else:
_reenter_event_type = QtCore.QEvent.Type(event_hint)
async def wait_signal(signal: "QtCore.SignalInstance") -> typing.Tuple[object, ...]:
"""Block for the next emission of ``signal`` and return the emitted arguments.
Warning:
In many cases this can result in a race condition since you are unable to
first connect the signal and then wait for it.
Args:
signal: The signal instance to wait for emission of.
Returns:
A tuple containing the values emitted by the signal.
"""
event = trio.Event()
result: typing.Tuple[object, ...] = ()
def slot(*args: object) -> None:
"""Receive and store the emitted arguments and set the event so we can continue.
Args:
args: The arguments emitted from the signal.
"""
nonlocal result
result = args
event.set()
with qtrio._qt.connection(signal, slot):
await event.wait()
return result
@attr.s(auto_attribs=True, frozen=True, slots=True, eq=False)
class Emission:
"""Stores the emission of a signal including the emitted arguments. Can be
compared against a signal instance to check the source. Do not construct this class
directly. Instead, instances will be received through a channel created by
:func:`qtrio.enter_emissions_channel`.
Note:
Each time you access a signal such as ``a_qobject.some_signal`` you get a
different signal instance object so the ``signal`` attribute generally will not
be the same object. A signal instance is a ``QtCore.SignalInstance`` in PySide or
``QtCore.pyqtBoundSignal`` in PyQt.
"""
signal: "QtCore.SignalInstance"
"""An instance of the original signal."""
args: typing.Tuple[object, ...]
"""A tuple of the arguments emitted by the signal."""
def is_from(self, signal: "QtCore.SignalInstance") -> bool:
"""Check if this emission came from ``signal``.
Args:
signal: The signal instance to check for being the source.
Returns:
Whether the passed signal was the source of this emission.
"""
# bool() to accomodate SignalInstance being typed Any right now...
return bool(self.signal == signal)
def __eq__(self, other: object) -> bool:
if type(other) != type(self):
return False
# TODO: workaround for https://github.com/python/mypy/issues/4445
if not isinstance(other, type(self)): # pragma: no cover
return False
return self.is_from(signal=other.signal) and self.args == other.args
@attr.s(auto_attribs=True, frozen=True)
class EmissionsChannelSlot:
internal_signal: "QtCore.SignalInstance"
send_channel: trio.MemorySendChannel
def slot(
self,
*args: object,
) -> None:
try:
self.send_channel.send_nowait(
Emission(signal=self.internal_signal, args=args)
)
except (trio.WouldBlock, trio.ClosedResourceError):
# TODO: log this or... ?
pass
@attr.s(auto_attribs=True)
class Emissions:
"""Hold elements useful for the application to work with emissions from signals.
Do not construct this class directly. Instead, use
:func:`qtrio.enter_emissions_channel`.
"""
channel: trio.MemoryReceiveChannel
"""A memory receive channel to be fed by signal emissions."""
send_channel: trio.MemorySendChannel
"""A memory send channel collecting signal emissions."""
async def aclose(self) -> None:
"""Asynchronously close the send channel when signal emissions are no longer of
interest.
"""
await self.send_channel.aclose()
@async_generator.asynccontextmanager
async def open_emissions_channel(
signals: typing.Collection["QtCore.SignalInstance"],
max_buffer_size: float = math.inf,
) -> typing.AsyncGenerator[Emissions, None]:
"""Create a memory channel fed by the emissions of the signals. Each signal
emission will be converted to a :class:`qtrio.Emission` object. On exit the send
channel is closed. Management of the receive channel is left to the caller.
Note:
Use this only if you need to process emissions *after* exiting the context
manager. Otherwise use :func:`qtrio.enter_emissions_channel`.
Args:
signals: A collection of signals which will be monitored for emissions.
max_buffer_size: When the number of unhandled emissions in the channel reaches
this limit then additional emissions will be silently thrown out the window.
Returns:
The emissions manager with the signals connected to it.
"""
# Infinite buffer because I don't think there's any use in storing the emission
# info in a `slot()` stack frame rather than in the memory channel. Perhaps in the
# future we can implement a limit beyond which events are thrown away to avoid
# infinite queueing. Maybe trio.MemorySendChannel.send_nowait() instead.
send_channel, receive_channel = trio.open_memory_channel[Emission](
max_buffer_size=max_buffer_size
)
async with send_channel:
with contextlib.ExitStack() as stack:
emissions = Emissions(channel=receive_channel, send_channel=send_channel)
for signal in signals:
slot = EmissionsChannelSlot(
internal_signal=signal, send_channel=send_channel
)
stack.enter_context(qtrio._qt.connection(signal, slot.slot))
yield emissions
@async_generator.asynccontextmanager
async def enter_emissions_channel(
signals: typing.Collection["QtCore.SignalInstance"],
max_buffer_size: float = math.inf,
) -> typing.AsyncGenerator[Emissions, None]:
"""Create a memory channel fed by the emissions of the signals and enter both the
send and receive channels' context managers.
Args:
signals: A collection of signals which will be monitored for emissions.
max_buffer_size: When the number of unhandled emissions in the channel reaches
this limit then additional emissions will be silently thrown out the window.
Returns:
The emissions manager.
"""
async with open_emissions_channel(
signals=signals, max_buffer_size=max_buffer_size
) as emissions:
async with emissions.channel:
async with emissions.send_channel:
yield emissions
class StarterProtocol(typing_extensions.Protocol):
def start(self, *args: object) -> None:
...
@attr.s(auto_attribs=True, frozen=True)
class DirectStarter:
slot: typing.Callable[..., typing.Awaitable[object]]
nursery: trio.Nursery
def start(self, *args: object) -> None:
self.nursery.start_soon(self.slot, *args)
@attr.s(auto_attribs=True, frozen=True)
class WrappedStarter:
slot: typing.Callable[..., typing.Awaitable[object]]
wrapper: typing.Callable[
[typing.Callable[..., typing.Awaitable[object]]], typing.Awaitable[object]
]
nursery: trio.Nursery
def start(self, *args: object) -> None:
self.nursery.start_soon(self.wrapper, self.slot, *args)
@attr.s(auto_attribs=True)
class EmissionsNursery:
"""Holds the nursery, exit stack, and wrapper needed to support connecting signals
to both async and sync slots in the nursery.
"""
nursery: trio.Nursery
"""The Trio nursery that will handle execution of the slots."""
exit_stack: contextlib.ExitStack
"""The exit stack that will manage the connections so they get disconnected."""
wrapper: typing.Optional[
typing.Callable[
[typing.Callable[..., typing.Awaitable[object]]],
typing.Awaitable[object],
]
] = None
"""The wrapper for handling the slots. This could, for example, handle exceptions
and present a dialog to avoid cancelling the entire nursery.
"""
def connect(
self,
signal: "QtCore.SignalInstance",
slot: typing.Callable[..., typing.Awaitable[object]],
) -> None:
"""Connect an async signal to this emissions nursery so when called the slot
will be run in the nursery.
"""
starter: StarterProtocol
if self.wrapper is None:
starter = DirectStarter(slot=slot, nursery=self.nursery)
else:
starter = WrappedStarter(
slot=slot, wrapper=self.wrapper, nursery=self.nursery
)
self.exit_stack.enter_context(qtrio._qt.connection(signal, starter.start))
def connect_sync(
self, signal: "QtCore.SignalInstance", slot: typing.Callable[..., object]
) -> None:
"""Connect to a sync slot to this emissions nursery so when called the slot will
be run in the nursery.
"""
async def async_slot(*args: object) -> None:
slot(*args)
self.connect(signal=signal, slot=async_slot)
@async_generator.asynccontextmanager
async def open_emissions_nursery(
until: typing.Optional["QtCore.SignalInstance"] = None,
wrapper: typing.Optional[typing.Callable[..., typing.Awaitable[object]]] = None,
) -> typing.AsyncGenerator[EmissionsNursery, None]:
"""Open a nursery for handling callbacks triggered by signal emissions. This allows
a 'normal' Qt callback structure while still executing the callbacks within a Trio
nursery such that errors have a place to go. Both async and sync callbacks can be
connected. Sync callbacks will be wrapped in an async call to allow execution in
the nursery.
Arguments:
until: Keep the nursery open until this signal is emitted.
wrapper: A wrapper for the callbacks such as to process exceptions.
Returns:
The emissions manager.
"""
async with trio.open_nursery() as nursery:
with contextlib.ExitStack() as exit_stack:
emissions_nursery = EmissionsNursery(
nursery=nursery,
exit_stack=exit_stack,
wrapper=wrapper,
)
if until is not None:
async with wait_signal_context(until):
yield emissions_nursery
else:
yield emissions_nursery
@async_generator.asynccontextmanager
async def wait_signal_context(
signal: "QtCore.SignalInstance",
) -> typing.AsyncGenerator[None, None]:
"""Connect a signal during the context and wait for it on exit. Presently no
mechanism is provided for retrieving the emitted arguments.
Args:
signal: The signal to connect to and wait for.
"""
event = trio.Event()
def slot(*args: object, **kwargs: object) -> None:
event.set()
with qtrio._qt.connection(signal=signal, slot=slot):
yield
await event.wait()
@attr.s(auto_attribs=True, frozen=True, slots=True)
class Outcomes:
"""This class holds an :class:`outcome.Outcome` from each of the Trio and the Qt
application execution. Do not construct instances directly. Instead, an instance
will be returned from :func:`qtrio.run` or available on instances of
:attr:`qtrio.Runner.outcomes`.
"""
qt: typing.Optional[outcome.Outcome] = None
"""The Qt application :class:`outcome.Outcome`"""
trio: typing.Optional[outcome.Outcome] = None
"""The Trio async function :class:`outcome.Outcome`"""
def unwrap(self) -> object:
"""Unwrap either the Trio or Qt outcome. First, errors are given priority over
success values. Second, the Trio outcome gets priority over the Qt outcome.
Returns:
Whatever captured value was selected.
Raises:
Exception: Whatever captured exception was selected.
qtrio.NoOutcomesError: if no value or exception has been captured.
"""
if self.trio is not None:
# highest priority to the Trio outcome, if it is an error we are done
result = self.trio.unwrap()
# since a Trio result is higher priority, we only care if Qt gave an error
if self.qt is not None:
self.qt.unwrap()
# no Qt error so go ahead and return the Trio result
return result
elif self.qt is not None:
# either it is a value that gets returned or an error that gets raised
return self.qt.unwrap()
# neither Trio nor Qt outcomes have been set so we have nothing to unwrap()
raise qtrio.NoOutcomesError()
def run(
async_fn: typing.Callable[..., typing.Awaitable[object]],
*args: object,
done_callback: typing.Optional[typing.Callable[[Outcomes], None]] = None,
clock: typing.Optional[trio.abc.Clock] = None,
instruments: typing.Sequence[trio.abc.Instrument] = (),
) -> object:
"""Run a Trio-flavored async function in guest mode on a Qt host application, and
return the result.
Args:
async_fn: The async function to run.
args: Positional arguments to pass to `async_fn`.
done_callback: See :class:`qtrio.Runner.done_callback`.
clock: See :class:`qtrio.Runner.clock`.
instruments: See :class:`qtrio.Runner.instruments`.
Returns:
The object returned by ``async_fn``.
"""
runner = Runner(
done_callback=done_callback, clock=clock, instruments=list(instruments)
)
runner.run(async_fn, *args)
return runner.outcomes.unwrap()
def outcome_from_application_return_code(return_code: int) -> outcome.Outcome:
"""Create either an :class:`outcome.Value` in the case of a 0 `return_code` or an
:class:`outcome.Error` with a :class:`ReturnCodeError` otherwise.
Args:
return_code: The return code to be processed.
Returns:
The outcome wrapping the passed in return code.
"""
if return_code == 0:
return outcome.Value(return_code)
return outcome.Error(qtrio.ReturnCodeError(return_code))
def maybe_build_application() -> "QtGui.QGuiApplication":
"""Create a new Qt application object if one does not already exist.
Returns:
The Qt application object.
"""
from qts import QtWidgets # noqa: F811
application: QtCore.QCoreApplication
# TODO: https://bugreports.qt.io/browse/PYSIDE-1467
if qts.is_pyside_5_wrapper: # pragma: no cover
maybe_application = typing.cast(
typing.Optional["QtCore.QCoreApplication"],
QtWidgets.QApplication.instance(),
)
else:
maybe_application = QtWidgets.QApplication.instance()
if maybe_application is None:
application = QtWidgets.QApplication(sys.argv[1:])
else:
application = maybe_application
application.setQuitOnLastWindowClosed(False)
return application
def create_reenter() -> "qtrio.qt.Reenter":
import qtrio.qt
return qtrio.qt.Reenter()
def _early_quit_warning() -> None:
warnings.warn(
message="The Qt application quit early. See https://qtrio.readthedocs.io/en/stable/lifetimes.html",
category=qtrio.ApplicationQuitWarning,
)
@attr.s(auto_attribs=True, slots=True)
class Runner:
"""This class helps run Trio in guest mode on a Qt host application."""
application: "QtGui.QGuiApplication" = attr.ib(factory=maybe_build_application)
"""The Qt application object to run as the host. If not set before calling
:meth:`run` the application will be created as
``QtWidgets.QApplication(sys.argv[1:])`` and ``.setQuitOnLastWindowClosed(False)``
will be called on it to allow the application to continue throughout the lifetime of
the async function passed to :meth:`qtrio.Runner.run`.
"""
quit_application: bool = True
"""When true, the :meth:`done_callback` method will quit the application when the
async function passed to :meth:`qtrio.Runner.run` has completed.
"""
clock: typing.Optional[trio.abc.Clock] = None
"""The clock to use for this run. This is primarily used to speed up tests that
include timeouts. The value will be passed on to
:func:`trio.lowlevel.start_guest_run`.
"""
instruments: typing.Sequence[trio.abc.Instrument] = ()
"""The instruments to use for this run. The value will be passed on to
:func:`trio.lowlevel.start_guest_run`.
"""
reenter: "qtrio.qt.Reenter" = attr.ib(factory=create_reenter)
"""The :class:`QtCore.QObject` instance which will receive the events requesting
execution of the needed Trio and user code in the host's event loop and thread.
"""
done_callback: typing.Optional[typing.Callable[[Outcomes], None]] = attr.ib(
default=None
)
"""The builtin :meth:`done_callback` will be passed to
:func:`trio.lowlevel.start_guest_run` but will call the callback passed here before
(maybe) quitting the application. The :class:`outcome.Outcome` from the completion
of the async function passed to :meth:`run` will be passed to this callback.
"""
outcomes: Outcomes = attr.ib(factory=Outcomes, init=False)
"""The outcomes from the Qt and Trio runs."""
cancel_scope: trio.CancelScope = attr.ib(default=None, init=False)
"""An all encompassing cancellation scope for the Trio execution."""
_done: bool = attr.ib(default=False, init=False)
"""Just an indicator that the run is done. Presently used only for a test."""
def run(
self,
async_fn: typing.Callable[..., typing.Awaitable[object]],
*args: object,
execute_application: bool = True,
) -> Outcomes:
"""Start the guest loop executing ``async_fn``.
Args:
async_fn: The async function to be run in the Qt host loop by the Trio
guest.
args: Arguments to pass when calling ``async_fn``.
execute_application: If True, the Qt application will be executed and this
call will block until it finishes.
Returns:
If ``execute_application`` is true, a :class:`qtrio.Outcomes` containing
outcomes from the Qt application and ``async_fn`` will be returned.
Otherwise, an empty :class:`qtrio.Outcomes`.
"""
if _reenter_event_type is None:
register_event_type()
trio.lowlevel.start_guest_run(
self.trio_main,
async_fn,
args,
run_sync_soon_threadsafe=self.run_sync_soon_threadsafe,
done_callback=self.trio_done,
clock=self.clock,
instruments=self.instruments,
)
if self.quit_application:
self.application.aboutToQuit.connect(_early_quit_warning)
if execute_application:
return_code = qts.util.exec(self.application)
self.outcomes = attr.evolve(
self.outcomes,
qt=outcome_from_application_return_code(return_code),
)
return self.outcomes
def run_sync_soon_threadsafe(self, fn: typing.Callable[[], object]) -> None:
"""Helper for the Trio guest to execute a sync function in the Qt host
thread when called from the Trio guest thread. This call will not block waiting
for completion of ``fn`` nor will it return the result of calling ``fn``.
Args:
fn: A no parameter callable.
"""
import qtrio.qt
event = qtrio.qt.ReenterEvent(fn=fn)
self.application.postEvent(self.reenter, event)
async def trio_main(
self,
async_fn: typing.Callable[..., typing.Awaitable[object]],
args: typing.Tuple[object, ...],
) -> object:
"""Will be run as the main async function by the Trio guest. If it is a GUI
application then it creates a cancellation scope to be cancelled when
:meth:`QtGui.QGuiApplication.lastWindowClosed` is emitted. Within this scope
the application's ``async_fn`` will be run and passed ``args``.
Args:
async_fn: The application's main async function to be run by Trio in the Qt
host's thread.
args: Positional arguments to be passed to ``async_fn``
Returns:
The result returned by `async_fn`.
"""
from qts import QtGui
result: object = None
with trio.CancelScope() as self.cancel_scope:
with contextlib.ExitStack() as exit_stack:
if (
isinstance(self.application, QtGui.QGuiApplication)
and self.application.quitOnLastWindowClosed()
):
exit_stack.enter_context(
qtrio._qt.connection(
signal=self.application.lastWindowClosed,
slot=self.cancel_scope.cancel,
)
)
result = await async_fn(*args)
return result
def trio_done(self, run_outcome: outcome.Outcome) -> None:
"""Will be called after the Trio guest run has finished. This allows collection
of the :class:`outcome.Outcome` and execution of any application provided done
callback. Finally, if :attr:`qtrio.Runner.quit_application` was set when
creating the instance then the Qt application will be requested to quit.
Actions such as outputting error information or unwrapping the outcomes need
to be further considered.
Arguments:
run_outcome: The outcome of the Trio guest run.
"""
self.outcomes = attr.evolve(self.outcomes, trio=run_outcome)
if self.done_callback is not None:
self.done_callback(self.outcomes)
if self.quit_application:
self.application.aboutToQuit.disconnect(_early_quit_warning)
self.application.quit()
self._done = True