Skip to content

Commit 476f3c3

Browse files
committed
UNDER_THE_HOOD.md: add section on debug code.
1 parent 2ec7ef7 commit 476f3c3

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

TUTORIAL.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Application of uasyncio to hardware interfaces
22

3+
This tutorial is intended for users having varying levels of experience with
4+
asyncio and includes a section for complete beginners.
5+
36
# Contents
47

58
0. [Introduction](./TUTORIAL.md#0-introduction)
@@ -82,6 +85,9 @@ Except where detailed below, `asyncio` features of versions >3.4 are
8285
unsupported. As stated above it is a subset; this document identifies supported
8386
features.
8487

88+
This tutoial advocates a consistent programming style with good compatibility
89+
with CPython V3.5 and above.
90+
8591
## 0.1 Installing uasyncio on bare metal
8692

8793
MicroPython libraries are located on [PyPi](https://pypi.python.org/pypi).

UNDER_THE_HOOD.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ wishing to modify it.
99

1010
Where the versions differ, this explanation relates to the `fast_io` version.
1111
Differences are largely in `__init__.py`: the scheduling algorithm in `core.py`
12-
is little changed.
12+
is little changed. Note that the code in `fast_io` contains additional comments
13+
to explain its operation.
1314

1415
This doc assumes a good appreciation of the use of `uasyncio`. An understanding
1516
of Python generators is also essential, in particular the use of `yield from`
@@ -257,6 +258,27 @@ I/O queue has been instantiated.
257258

258259
Writing is handled similarly.
259260

261+
# Debug code
262+
263+
The official `uasyncio` contains considerable explicit debug code: schedulers
264+
are hard to debug. There is code which I believe is for debugging purposes and
265+
some I have added myself for this purpose. The aim is to ensure that, if an
266+
error causes a coro to be scheduled when it shouldn't be, an exception is
267+
thrown. The alternative is weird, hard to diagnose, behaviour.
268+
These are the instances.
269+
270+
[pend_throw(false)](https://github.com/peterhinch/micropython-lib/blob/f20d89c6aad9443a696561ca2a01f7ef0c8fb302/uasyncio.core/uasyncio/core.py#L119)
271+
[also here](https://github.com/peterhinch/micropython-lib/blob/f20d89c6aad9443a696561ca2a01f7ef0c8fb302/uasyncio.core/uasyncio/core.py#L123)
272+
I think the intention here is to throw an exception (exception doesn't inherit
273+
from Exception) if it is scheduled incorrectly. Correct scheduling coutermands
274+
this:
275+
[here](https://github.com/peterhinch/micropython-lib/blob/819562312bae807ce0d01aa8ad36a13c22ba9e40/uasyncio/uasyncio/__init__.py#L97)
276+
[and here](https://github.com/peterhinch/micropython-lib/blob/819562312bae807ce0d01aa8ad36a13c22ba9e40/uasyncio/uasyncio/__init__.py#L114)
277+
The `rdobjmap` and `wrobjmap` dictionary entries are invalidated
278+
[here](https://github.com/peterhinch/micropython-lib/blob/819562312bae807ce0d01aa8ad36a13c22ba9e40/uasyncio/uasyncio/__init__.py#L91)
279+
[and here](https://github.com/peterhinch/micropython-lib/blob/819562312bae807ce0d01aa8ad36a13c22ba9e40/uasyncio/uasyncio/__init__.py#L101)
280+
This has the same aim: if an attempt is made incorrectly to reschedule them, an
281+
260282
# Modifying uasyncio
261283

262284
The library is designed to be extensible. By following these guidelines a

0 commit comments

Comments
 (0)