@@ -7,8 +7,8 @@ polled. Such polling is efficient because it is handled in C using
7
7
` select.poll ` , and because the coroutine accessing the device is descheduled
8
8
until polling succeeds.
9
9
10
- Unfortunately current ` uasyncio ` polls I/O with a relatively high degree of
11
- latency. It also has a bug whereby bidirectional devices such as UARTS could
10
+ Unfortunately official ` uasyncio ` polls I/O with a relatively high degree of
11
+ latency. It also has a bug whereby bidirectional devices such as UARTS can
12
12
fail to handle concurrent input and output.
13
13
14
14
This version has the following changes:
@@ -18,7 +18,9 @@ This version has the following changes:
18
18
* Callbacks can similarly be scheduled with low priority.
19
19
* The bug with read/write device drivers is fixed (forthcoming PR).
20
20
* An assertion failure is produced if ` create_task ` or ` run_until_complete `
21
- is called with a generator function [ PR292] ( https://github.com/micropython/micropython-lib/pull/292 ) .
21
+ is called with a generator function
22
+ [ PR292] ( https://github.com/micropython/micropython-lib/pull/292 ) . This traps
23
+ a common coding error which otherwise results in silent failure.
22
24
23
25
A key advantage of this version is that priority device drivers are written
24
26
entirely by using the officially-supported technique for writing stream I/O
@@ -35,8 +37,8 @@ be deleted from your system.
35
37
The facility for low priority coros formerly provided by ` asyncio_priority.py `
36
38
is now implemented.
37
39
38
- This modified version also provides for ultra low power consumption using a
39
- module documented [ here] ( ./lowpower/README.md ) .
40
+ This version also provides for ultra low power consumption using a module
41
+ documented [ here] ( ./lowpower/README.md ) .
40
42
41
43
###### [ Main README] ( ./README.md )
42
44
@@ -69,6 +71,10 @@ above two files implemented as frozen bytecode. See
69
71
[ ESP Platforms] ( ./FASTPOLL.md#6-esp-platforms ) for general comments on the
70
72
suitability of ESP platforms for systems requiring fast response.
71
73
74
+ It is possible to load modules in the filesystem in preference to frozen ones
75
+ by modifying ` sys.path ` . However the ESP8266 probably has too little RAM for
76
+ this to be useful.
77
+
72
78
## 1.1 Benchmarks
73
79
74
80
The benchmarks directory contains files demonstrating the performance gains
@@ -82,14 +88,14 @@ features. Documentation is in the code.
82
88
* ` benchmarks/rate_esp.py ` As above for ESP32 and ESP8266.
83
89
* ` benchmarks/rate_fastio.py ` Measures the rate at which coros can be scheduled
84
90
if the fast I/O mechanism is used but no I/O is pending.
91
+ * ` benchmarks/call_lp.py ` Demos low priority callbacks.
92
+ * ` benchmarks/overdue.py ` Demo of maximum overdue feature.
93
+ * ` benchmarks/priority_test.py ` Cancellation of low priority coros.
85
94
* ` fast_io/ms_timer.py ` Provides higher precision timing than ` wait_ms() ` .
86
- * ` fast_io/ms_timer .py ` Test/demo program for above.
95
+ * ` fast_io/ms_timer_test .py ` Test/demo program for above.
87
96
* ` fast_io/pin_cb.py ` Demo of an I/O device driver which causes a pin state
88
97
change to trigger a callback.
89
98
* ` fast_io/pin_cb_test.py ` Demo of above.
90
- * ` benchmarks/call_lp.py ` Demos low priority callbacks.
91
- * ` benchmarks/overdue.py ` Demo of maximum overdue feature.
92
- * ` priority_test.py ` Cancellation of low priority coros.
93
99
94
100
With the exceptions of ` call_lp ` , ` priority ` and ` rate_fastio ` , benchmarks can
95
101
be run against the official and priority versions of usayncio.
@@ -115,8 +121,8 @@ realised.
115
121
It also enables coros to yield control in a way which prevents them from
116
122
competing with coros which are ready for execution. Coros which have yielded in
117
123
a low priority fashion will not be scheduled until all "normal" coros are
118
- waiting on a nonzero timeout. The benchmarks show that the improvement can
119
- exceed two orders of magnitude.
124
+ waiting on a nonzero timeout. The benchmarks show that the improvement in the
125
+ accuracy of time delays can exceed two orders of magnitude.
120
126
121
127
## 2.1 Latency
122
128
@@ -248,11 +254,12 @@ Examples are:
248
254
249
255
The ` fast_io ` version adds ` ioq_len=0 ` and ` lp_len=0 ` arguments to
250
256
` get_event_loop ` . These determine the lengths of I/O and low priority queues.
251
- The zero defaults cause the queues not to be instantiated. The scheduler
252
- operates as per the official version. If an I/O queue length > 0 is provided,
253
- I/O performed by ` StreamReader ` and ` StreamWriter ` objects will be prioritised
254
- over other coros. If a low priority queue length > 0 is specified, tasks have
255
- an option to yield in such a way to minimise competition with other tasks.
257
+ The zero defaults cause the queues not to be instantiated, in which case the
258
+ scheduler operates as per the official version. If an I/O queue length > 0 is
259
+ provided, I/O performed by ` StreamReader ` and ` StreamWriter ` objects is
260
+ prioritised over other coros. If a low priority queue length > 0 is specified,
261
+ tasks have an option to yield in such a way to minimise their competition with
262
+ other tasks.
256
263
257
264
Arguments to ` get_event_loop() ` :
258
265
1 . ` runq_len=16 ` Length of normal queue. Default 16 tasks.
@@ -266,7 +273,7 @@ Arguments to `get_event_loop()`:
266
273
267
274
Device drivers which are to be capable of running at high priority should be
268
275
written to use stream I/O: see
269
- [ Writing IORead device drivers] ( ./TUTORIAL.md#54-writing-ioread -device-drivers ) .
276
+ [ Writing streaming device drivers] ( ./TUTORIAL.md#54-writing-streaming -device-drivers ) .
270
277
271
278
The ` fast_io ` version will schedule I/O whenever the ` ioctl ` reports a ready
272
279
status. This implies that devices which become ready very soon after being
@@ -304,13 +311,14 @@ See [Low priority callbacks](./FASTPOLL.md#35-low-priority-callbacks)
304
311
305
312
## 3.3 Other Features
306
313
307
- The version has a ` version ` variable containing 'fast_io'. This enables the
308
- presence of this version to be determined at runtime.
309
-
310
- It also supports a ` got_event_loop() ` function returning a ` bool ` : ` True ` if
311
- the event loop has been instantiated. The purpose is to enable code which uses
312
- the event loop to raise an exception if the event loop was not instantiated.
314
+ Variable:
315
+ * ` version ` Contains 'fast_io'. Enables the presence of this version to be
316
+ determined at runtime.
313
317
318
+ Function:
319
+ * ` got_event_loop() ` No arg. Returns a ` bool ` : ` True ` if the event loop has
320
+ been instantiated. Enables code using the event loop to raise an exception if
321
+ the event loop was not instantiated:
314
322
``` python
315
323
class Foo ():
316
324
def __init__ (self ):
@@ -357,6 +365,7 @@ overdue. For the reasoning behind this consider this code:
357
365
358
366
``` python
359
367
import uasyncio as asyncio
368
+ loop = asyncio.get_event_loop(lp_len = 16 )
360
369
361
370
async def foo ():
362
371
while True :
@@ -404,7 +413,8 @@ The following `EventLoop` methods enable callback functions to be scheduled
404
413
to run when all normal coros are waiting on a delay or when ` max_overdue_ms `
405
414
has elapsed:
406
415
407
- ` call_after ` Schedule a callback with low priority. Positional args:
416
+ ` call_after(delay, callback, *args) ` Schedule a callback with low priority.
417
+ Positional args:
408
418
1 . ` delay ` Minimum delay in seconds. May be a float or integer.
409
419
2 . ` callback ` The callback to run.
410
420
3 . ` *args ` Optional comma-separated positional args for the callback.
0 commit comments