Skip to content

Commit c57486b

Browse files
committed
Fixs to FASTPOLL.md.
1 parent 14bcf95 commit c57486b

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

FASTPOLL.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ polled. Such polling is efficient because it is handled in C using
77
`select.poll`, and because the coroutine accessing the device is descheduled
88
until polling succeeds.
99

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
1212
fail to handle concurrent input and output.
1313

1414
This version has the following changes:
@@ -18,7 +18,9 @@ This version has the following changes:
1818
* Callbacks can similarly be scheduled with low priority.
1919
* The bug with read/write device drivers is fixed (forthcoming PR).
2020
* 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.
2224

2325
A key advantage of this version is that priority device drivers are written
2426
entirely by using the officially-supported technique for writing stream I/O
@@ -35,8 +37,8 @@ be deleted from your system.
3537
The facility for low priority coros formerly provided by `asyncio_priority.py`
3638
is now implemented.
3739

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).
4042

4143
###### [Main README](./README.md)
4244

@@ -69,6 +71,10 @@ above two files implemented as frozen bytecode. See
6971
[ESP Platforms](./FASTPOLL.md#6-esp-platforms) for general comments on the
7072
suitability of ESP platforms for systems requiring fast response.
7173

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+
7278
## 1.1 Benchmarks
7379

7480
The benchmarks directory contains files demonstrating the performance gains
@@ -82,14 +88,14 @@ features. Documentation is in the code.
8288
* `benchmarks/rate_esp.py` As above for ESP32 and ESP8266.
8389
* `benchmarks/rate_fastio.py` Measures the rate at which coros can be scheduled
8490
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.
8594
* `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.
8796
* `fast_io/pin_cb.py` Demo of an I/O device driver which causes a pin state
8897
change to trigger a callback.
8998
* `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.
9399

94100
With the exceptions of `call_lp`, `priority` and `rate_fastio`, benchmarks can
95101
be run against the official and priority versions of usayncio.
@@ -115,8 +121,8 @@ realised.
115121
It also enables coros to yield control in a way which prevents them from
116122
competing with coros which are ready for execution. Coros which have yielded in
117123
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.
120126

121127
## 2.1 Latency
122128

@@ -248,11 +254,12 @@ Examples are:
248254

249255
The `fast_io` version adds `ioq_len=0` and `lp_len=0` arguments to
250256
`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.
256263

257264
Arguments to `get_event_loop()`:
258265
1. `runq_len=16` Length of normal queue. Default 16 tasks.
@@ -266,7 +273,7 @@ Arguments to `get_event_loop()`:
266273

267274
Device drivers which are to be capable of running at high priority should be
268275
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).
270277

271278
The `fast_io` version will schedule I/O whenever the `ioctl` reports a ready
272279
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)
304311

305312
## 3.3 Other Features
306313

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.
313317

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:
314322
```python
315323
class Foo():
316324
def __init__(self):
@@ -357,6 +365,7 @@ overdue. For the reasoning behind this consider this code:
357365

358366
```python
359367
import uasyncio as asyncio
368+
loop = asyncio.get_event_loop(lp_len=16)
360369

361370
async def foo():
362371
while True:
@@ -404,7 +413,8 @@ The following `EventLoop` methods enable callback functions to be scheduled
404413
to run when all normal coros are waiting on a delay or when `max_overdue_ms`
405414
has elapsed:
406415

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:
408418
1. `delay` Minimum delay in seconds. May be a float or integer.
409419
2. `callback` The callback to run.
410420
3. `*args` Optional comma-separated positional args for the callback.

0 commit comments

Comments
 (0)