Skip to content

Commit 14618c7

Browse files
committed
Support uasyncio V2.0.
1 parent c414c20 commit 14618c7

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

FASTPOLL.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@ This document describes a "priority" version of uasyncio. Its purpose is to
44
provide a simple priority mechanism to facilitate the design of applications
55
with improved millisecond-level timing accuracy and reduced scheduling latency.
66

7-
V0.2 Dec 2017. A single module designed to work with the official `uasyncio`
8-
library. This requires uasyncio.core V1.7 which was released on 16th Dec 2017,
9-
with firmware of that date or later. It does not yet support `uasyncio` V2.0.
7+
V0.3 Feb 2018. A single module designed to work with the official `uasyncio`
8+
library. This requires `uasyncio` V2.0 which requires firmware dated
9+
22nd Feb 2018 or later.
1010

1111
**API CHANGES**
12-
The API has been changed to simplify the code and to improve consistency.
13-
1. `call_after_ms` Args have changed to match other methods.
14-
2. `get_event_loop` now only takes two args - setting the maximum overdue time
15-
must be done via the `max_overdue_ms` method.
12+
V2.0 of `uasyncio` changed the arguments to `get_event_loop` so this version
13+
has corresponding changes. See [section 3](./FASTPOLL.md#3-a-solution).
1614

1715
###### [Main README](./README.md)
1816

1917
# Contents
2018

2119
1. [Installation](./FASTPOLL.md#1-installation)
2220

23-
1.1 [Benchmarks](./FASTPOLL.md#11-benchmarks)
21+
1.1 [Benchmarks](./FASTPOLL.md#11-benchmarks) Benchmark and demo programs.
2422

2523
2. [Rationale](./FASTPOLL.md#2-rationale)
2624

@@ -51,29 +49,34 @@ The API has been changed to simplify the code and to improve consistency.
5149
# 1. Installation
5250

5351
Install and test uasyncio on the target hardware. Copy `asyncio_priority.py`
54-
to the target.
52+
to the target. Users of previous versions should update any of the benchmark
53+
programs which are to be run.
5554

5655
In MicroPython 1.9 `uasyncio` was implemented as a frozen module on the
57-
ESP8266. The `asyncio_priority.py` module may be put in the filesystem or
58-
compiled as frozen bytecode. See [ESP Platforms](./FASTPOLL.md#6-esp-platforms)
59-
for general comments on the suitability of ESP platforms for systems requiring
60-
fast response.
56+
ESP8266. This version is not compatible with `asyncio_priority.py`. Given the
57+
limited resources of the ESP8266 `uasyncio` and `uasyncio_priority` should be
58+
implemented as frozen bytecode. See
59+
[ESP Platforms](./FASTPOLL.md#6-esp-platforms) for general comments on the
60+
suitability of ESP platforms for systems requiring fast response.
6161

6262
## 1.1 Benchmarks
6363

6464
The benchmarks directory contains files demonstrating the performance gains
6565
offered by prioritisation. They also offer illustrations of the use of these
6666
features. Documentation is in the code.
6767

68-
* latency.py Shows the effect on latency with and without low priority usage.
69-
* timing.py Shows the effect on timing with and without low priority usage.
70-
* rate.py Shows the frequency with which the official uasyncio schedules
71-
minimal coroutines (coros).
72-
* rate_p.py As above, but measures the overhead of the priority extension.
73-
* call_lp.py Demos low priority callbacks.
74-
* overdue.py Demo of maximum overdue feature.
75-
* priority.py Demo of high priority coro.
76-
* priority_test.py Cancellation of low priority coros.
68+
* `benchmarks/latency.py` Shows the effect on latency with and without low
69+
priority usage.
70+
* `benchmarks/timing.py` Shows the effect on timing with and without low
71+
priority usage.
72+
* ``benchmarks/rate.py` Shows the frequency with which the official uasyncio
73+
schedules minimal coroutines (coros).
74+
* `benchmarks/rate_p.py` As above, but measures the overhead of the priority
75+
extension.
76+
* `benchmarks/call_lp.py` Demos low priority callbacks.
77+
* `benchmarks/overdue.py` Demo of maximum overdue feature.
78+
* `benchmarks/priority.py` Demo of high priority coro.
79+
* `priority_test.py` Cancellation of low priority coros.
7780

7881
With the exceptions of call_lp and priority.py, benchmarks can be run against
7982
the official and priority versions of usayncio.

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@ This GitHub repository consists of the following parts:
1818
mechanism. With suitable application design this improves the rate at which
1919
devices can be polled and improves the accuracy of time delays. Also provides
2020
for low priority tasks which are only scheduled when normal tasks are paused.
21-
NOTE: this currently supports uasyncio V1.7.1.
21+
NOTE: this requires uasyncio V2.0.
2222
* [Communication between devices](./syncom_as/README.md) Enables MicroPython
2323
boards to communicate without using a UART. Primarily intended to enable a
2424
a Pyboard-like device to achieve bidirectional communication with an ESP8266.
2525

2626
# 2. Version and installation of uasyncio
2727

28-
This has become more involved owing to the development of Paul Sokolovsky's
29-
fork. At the time of writing his fork supports `uasyncio` version 2.0. The
30-
version on PyPI is also V2.0.
28+
The documentation and code in this repository are based on `uasyncio` version
29+
2.0, which is the version on PyPi. This requires firmware dated 22nd Feb 2018
30+
or later.
3131

32-
The version in [micropython-lib](https://github.com/micropython/micropython-lib)
33-
is version 1.7.1.
32+
Version 2.0 brings only one API change over V1.7.1, namely the arguments to
33+
`get_event_loop()`. Unless using the priority version all test programs and
34+
code samples use default args so will work under either version. The priority
35+
version requires the later version and firmware.
3436

35-
With the exception of the priority version all docs and code samples should be
36-
compatible with both versions. Testing has been done under V1.7.1.
37+
[Paul Sokolovsky's library](https://github.com/pfalcon/micropython-lib) has the
38+
latest `uasyncio` code. At the time of writing (Feb 27th 2018) the version in
39+
[micropython-lib](https://github.com/micropython/micropython-lib) is 1.7.1.
3740

3841
See [tutorial](./TUTORIAL.md#installing-uasyncio-on-bare-metal) for
3942
installation instructions.

TUTORIAL.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ $ python3 -m micropip.py install -p ~/syn micropython-uasyncio
5656
```
5757

5858
The `uasyncio` modules may be frozen as bytecode in the usual way, by placing
59-
the `uasyncio` directory in the port's `modules` directory and rebuilding.
59+
the `uasyncio` and `collections` directories in the port's `modules` directory
60+
and rebuilding.
6061

6162
###### [Main README](./README.md)
6263

@@ -454,7 +455,7 @@ ineffective. It will not receive the `TimeoutError` until it has acquired the
454455
lock. The same observation applies to task cancellation.
455456

456457
The module `asyn.py` offers a `Lock` class which works in these situations
457-
[Full details.](./PRIMITIVES.md#32-class-lock). It is significantly less
458+
[full details](./PRIMITIVES.md#32-class-lock). It is significantly less
458459
efficient than the official class but supports additional interfaces as per the
459460
CPython version including context manager usage.
460461

@@ -630,8 +631,7 @@ controlled. Documentation of this is in the code.
630631

631632
## 3.6 Task cancellation
632633

633-
This requires `uasyncio` V1.7.1 which was released on 7th Jan 2018, with
634-
firmware of that date or later.
634+
This requires `uasyncio` V1.7.1 or later, with suitably recent firmware.
635635

636636
`uasyncio` now provides a `cancel(coro)` function. This works by throwing an
637637
exception to the coro in a special way: cancellation is deferred until the coro

asyncio_priority.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def schedule_lp_task(self, cur_task, tnow):
4646
tim = time.ticks_diff(t, tnow)
4747
to_run = self._max_overdue_ms > 0 and tim < -self._max_overdue_ms
4848
if not to_run: # No overdue LP task.
49-
if len(self.runq):
49+
if len(self.runq): # zero delay tasks go straight to runq
5050
return False
5151
to_run = tim <= 0 # True if LP task is due
5252
if to_run and self.waitq: # Set False if a normal tasks is due.
@@ -199,11 +199,11 @@ def run_forever(self):
199199
# need to feed anything to the next invocation of coroutine.
200200
# If that changes, need to pass that value below.
201201
if low_priority:
202-
self.call_after_ms(delay, cb)
202+
self.call_after_ms(delay, cb) # Put on lpq
203203
elif delay:
204-
self.call_later_ms(delay, cb)
204+
self.call_later_ms(delay, cb) # waitq
205205
else:
206-
self.call_soon(cb)
206+
self.call_soon(cb) # runq
207207

208208
# Wait until next waitq task or I/O availability
209209
delay = 0

0 commit comments

Comments
 (0)