@@ -1554,6 +1554,10 @@ application dependent.
1554
1554
An alternative approach is to use blocking sockets with ` StreamReader ` and
1555
1555
` StreamWriter ` instances to control polling.
1556
1556
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
+
1557
1561
###### [ Contents] ( ./TUTORIAL.md#contents )
1558
1562
1559
1563
## 6.7 Event loop constructor args
@@ -1571,7 +1575,7 @@ bar = some_module.Bar() # Constructor calls get_event_loop()
1571
1575
loop = asyncio.get_event_loop(runq_len = 40 , waitq_len = 40 )
1572
1576
```
1573
1577
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
1575
1579
the event loop immediately after importing ` uasyncio ` .
1576
1580
1577
1581
``` python
@@ -1581,6 +1585,17 @@ import some_module
1581
1585
bar = some_module.Bar() # The get_event_loop() call is now safe
1582
1586
```
1583
1587
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
+
1584
1599
Ref [ this issue] ( https://github.com/micropython/micropython-lib/issues/295 ) .
1585
1600
1586
1601
###### [ Contents] ( ./TUTORIAL.md#contents )
0 commit comments