Skip to content

Commit 702183d

Browse files
Adapt to the latest version of asyncgui and asyncgui-ext-clock
1 parent 71c9e76 commit 702183d

File tree

6 files changed

+233
-133
lines changed

6 files changed

+233
-133
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async def what_you_want_to_do(clock, label):
4646
await atk.event(label, '<Button>')
4747
print('C')
4848

49-
nursery.start(what_you_want_to_do(...))
49+
atk.start(what_you_want_to_do(...))
5050
```
5151

5252
## Installation
@@ -118,8 +118,8 @@ if __name__ == "__main__":
118118

119119
### threading
120120

121-
Unlike `Trio` and `asyncio`, `asynctkinter` doesn't provide any I/O functionalities,
122-
thus threads may be the best way to perform them without blocking the main thread:
121+
Unlike `trio` and `asyncio`, `asynckivy` does not provide any I/O primitives.
122+
Therefore, if you don’t want to implement your own, using threads may be the best way to perform I/O without blocking the main thread.
123123

124124
```python
125125
from concurrent.futures import ThreadPoolExecuter
@@ -130,16 +130,16 @@ executer = ThreadPoolExecuter()
130130
async def async_fn(clock: atk.Clock):
131131
# create a new thread, run a function inside it, then
132132
# wait for the completion of that thread
133-
r = await clock.run_in_thread(thread_blocking_operation, polling_interval=1.0)
133+
r = await atk.run_in_thread(clock, thread_blocking_operation)
134134
print("return value:", r)
135135

136136
# run a function inside a ThreadPoolExecuter, and wait for its completion.
137137
# (ProcessPoolExecuter is not supported)
138-
r = await clock.run_in_executer(executer, thread_blocking_operation, polling_interval=0.1)
138+
r = await atk.run_in_executer(clock, executer, thread_blocking_operation)
139139
print("return value:", r)
140140
```
141141

142-
Exceptions(not BaseExceptions) are propagated to the caller,
142+
Unhandled exceptions (excluding `BaseException` that is not `Exception`) are propagated to the caller
143143
so you can catch them like you do in synchronous code:
144144

145145
```python
@@ -148,7 +148,7 @@ import asynctkinter as atk
148148

149149
async def async_fn(clock: atk.Clock):
150150
try:
151-
r = await clock.run_in_thread(lambda: requests.get('htt...', timeout=10), ...)
151+
r = await atk.run_in_thread(clock, lambda: requests.get('htt...', timeout=10), ...)
152152
except requests.Timeout:
153153
print("TIMEOUT!")
154154
else:

examples/network_io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ async def main(*, clock: atk.Clock, root: tk.Tk):
1111
label.pack(expand=True)
1212
await atk.event(label, '<Button>')
1313
label['text'] = 'waiting for the server to respond...'
14-
res = await clock.run_in_thread(
14+
res = await atk.run_in_thread(
15+
clock,
1516
lambda: requests.get("https://httpbin.org/delay/2"),
1617
daemon=True,
1718
polling_interval=0.2,

examples/network_io_with_animation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ async def main(*, clock: atk.Clock, root: tk.Tk):
3535
button['text'] = 'cancel'
3636
async with atk.move_on_when(atk.event(button, "<Button>")) as cancel_tracker:
3737
label['text'] = 'first request...'
38-
await clock.run_in_thread(
38+
await atk.run_in_thread(
39+
clock,
3940
lambda: session.get("https://httpbin.org/delay/2"),
4041
daemon=True,
4142
polling_interval=0.4,
4243
)
4344
label['text'] = 'second request...'
44-
await clock.run_in_thread(
45+
await atk.run_in_thread(
46+
clock,
4547
lambda: session.get("https://httpbin.org/delay/2"),
4648
daemon=True,
4749
polling_interval=0.4,

0 commit comments

Comments
 (0)