Skip to content

Commit ff37d9b

Browse files
committed
TUTORIAL.md Add note re socket programming and update 6.7
1 parent 8328495 commit ff37d9b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

TUTORIAL.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,10 @@ application dependent.
15541554
An alternative approach is to use blocking sockets with `StreamReader` and
15551555
`StreamWriter` instances to control polling.
15561556

1557+
[This doc](https://github.com/peterhinch/micropython-samples/blob/master/resilient/README.md)
1558+
describes issues I encountered in WiFi applications which keep sockets open for
1559+
long periods, and offers a solution.
1560+
15571561
###### [Contents](./TUTORIAL.md#contents)
15581562

15591563
## 6.7 Event loop constructor args
@@ -1571,7 +1575,7 @@ bar = some_module.Bar() # Constructor calls get_event_loop()
15711575
loop = asyncio.get_event_loop(runq_len=40, waitq_len=40)
15721576
```
15731577

1574-
Given that importing a module can run code the only safe way is to instantiate
1578+
Given that importing a module can run code the safest way is to instantiate
15751579
the event loop immediately after importing `uasyncio`.
15761580

15771581
```python
@@ -1581,6 +1585,17 @@ import some_module
15811585
bar = some_module.Bar() # The get_event_loop() call is now safe
15821586
```
15831587

1588+
If imported modules do not run `uasyncio` code, another approach is to pass the
1589+
loop as an arg to any user code which needs it. Ensure that only the initially
1590+
loaded module calls `get_event_loop` e.g.
1591+
1592+
```python
1593+
import uasyncio as asyncio
1594+
import some_module
1595+
loop = asyncio.get_event_loop(runq_len=40, waitq_len=40)
1596+
bar = some_module.Bar(loop)
1597+
```
1598+
15841599
Ref [this issue](https://github.com/micropython/micropython-lib/issues/295).
15851600

15861601
###### [Contents](./TUTORIAL.md#contents)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy