event_loop
- Reference typing
Classes:
-
Host–A class that provides the necessary callbacks to run a gui event loop with a
backendstarted usingstart_guest_run.
Functions:
Host
¶
Bases: Generic[T]
A class that provides the necessary callbacks to run a gui event loop with a backend started using start_guest_run.
- Usage Command line Host options
-
Reference
event_loop
run
-
Reference
event_loop
Hostcurrent
- Reference event_loop
Methods:
-
current–The host running in the corresponding thread or current thread.
-
run–Run the loop in the current thread with a backend guest.
-
mainloop–Start the main event loop of the host.
Attributes:
-
start_guest(Callable[[], Any]) –A callback to start the guest. This must be called by a subclass.
Source code in src/async_kernel/event_loop/run.py
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 | |
start_guest
class-attribute
instance-attribute
¶
start_guest: Callable[[], Any] = staticmethod(lambda: None)
A callback to start the guest. This must be called by a subclass.
current
classmethod
¶
The host running in the corresponding thread or current thread.
Source code in src/async_kernel/event_loop/run.py
97 98 99 100 101 | |
run
classmethod
¶
run(
func: Callable[..., CoroutineType[Any, Any, T]], args: tuple, settings: RunSettings
) -> T
Run the loop in the current thread with a backend guest.
Source code in src/async_kernel/event_loop/run.py
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 | |
mainloop
¶
mainloop() -> T
Start the main event loop of the host.
Source code in src/async_kernel/event_loop/run.py
162 163 164 165 166 167 168 | |
run
¶
run(
func: Callable[..., CoroutineType[Any, Any, T]], args: tuple, settings: RunSettings
) -> T
Run func to completion asynchronously in the current thread using a backend
with an optional host (gui event loop).
The default backend is 'asyncio'.
If host is specified in settings. A host (gui) mainloop
will be started with the backend running as a guest (in the same thread). The backend
will execute func asynchronously to completion. Once completed the backend and host
are stopped and finally the result is returned.
Parameters:
-
(func¶Callable[..., CoroutineType[Any, Any, T]]) –A coroutine function.
-
(args¶tuple) –Args to use when calling func.
-
(settings¶RunSettings) –Settings to use when running func.
Custom host
A custom host can be started by subclassing Host and passed as the 'host_class' as the class or a dotted path if it is importable.
Source code in src/async_kernel/event_loop/run.py
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 | |
Bases: Host[T]
Methods:
-
run_sync_soon_threadsafe–Use Tcl "after" command to schedule a function call.
-
run_sync_soon_not_threadsafe–Use Tcl "after" command to schedule a function call from the main thread
-
done_callback–End the Tk app.
Source code in src/async_kernel/event_loop/tk_host.py
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 | |
run_sync_soon_threadsafe
¶
Use Tcl "after" command to schedule a function call.
Based on tkinter source comments
the issuance of the tcl call to after itself is thread-safe since it is sent
to the appropriate thread on line 1522.
Tkapp_ThreadSend effectively uses "after 0" while putting the command in the
event queue so the "after idle after 0"` incantation
is unnecessary here.
Compare to tkthread where definitely thread unsafe eval is used to send thread safe signals between tcl interpreters.
Source code in src/async_kernel/event_loop/tk_host.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
run_sync_soon_not_threadsafe
¶
run_sync_soon_not_threadsafe(fn) -> None
Use Tcl "after" command to schedule a function call from the main thread
If .call is called from the Tcl thread, the locking and sending are optimized away so it should be fast enough.
The incantation "after idle after 0"
avoids blocking the normal event queue when faced with an unending stream of tasks, for
example while True: await trio.sleep(0).
Source code in src/async_kernel/event_loop/tk_host.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
done_callback
¶
done_callback(outcome) -> None
End the Tk app.
Source code in src/async_kernel/event_loop/tk_host.py
89 90 91 92 93 94 95 | |
options: show_root_heading: true
Bases: Host[T]
- Usage Command line Host options
Source code in src/async_kernel/event_loop/qt_host.py
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 | |
options: show_root_heading: true