Skip to content

Commit 89c120e

Browse files
committed
Add async GPS driver.
1 parent c2aba5b commit 89c120e

12 files changed

+2818
-0
lines changed

TUTORIAL.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,46 @@ of `uasyncio` by forcing the coro to run, and possibly terminate, when it is
963963
still queued for execution. I haven't entirely thought through the implications
964964
of this, but it's a thoroughly bad idea.
965965

966+
There is a "gotcha" illustrated by this code sample. If allowed to run to
967+
completion it works as expected.
968+
969+
```python
970+
import uasyncio as asyncio
971+
async def foo():
972+
await asyncio.sleep(3)
973+
print('About to throw exception.')
974+
1/0
975+
976+
async def bar():
977+
try:
978+
await foo()
979+
except ZeroDivisionError:
980+
print('foo was interrupted by zero division') # Happens
981+
raise # Force shutdown to run by propagating to loop.
982+
except KeyboardInterrupt:
983+
print('foo was interrupted by ctrl-c') # NEVER HAPPENS
984+
raise
985+
986+
async def shutdown():
987+
print('Shutdown is running.') # Happens in both cases
988+
await asyncio.sleep(1)
989+
print('done')
990+
991+
loop = asyncio.get_event_loop()
992+
try:
993+
loop.run_until_complete(bar())
994+
except ZeroDivisionError:
995+
loop.run_until_complete(shutdown())
996+
except KeyboardInterrupt:
997+
print('Keyboard interrupt at loop level.')
998+
loop.run_until_complete(shutdown())
999+
```
1000+
1001+
However issuing a keyboard interrupt causes the exception to go to the event
1002+
loop. This is because `uasyncio.sleep` causes execution to be transferred to
1003+
the event loop. Consequently applications requiring cleanup code in response to
1004+
a keyboard interrupt should trap the exception at the event loop level.
1005+
9661006
###### [Contents](./TUTORIAL.md#contents)
9671007

9681008
# 5 Device driver examples

gps/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Calvin McCoy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)