File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -904,7 +904,9 @@ Timeouts are implemented by means of `uasyncio.wait_for()`. This takes as
904
904
arguments a coroutine and a timeout in seconds. If the timeout expires a
905
905
` TimeoutError ` will be thrown to the coro in such a way that the next time the
906
906
coro is scheduled for execution the exception will be raised. The coro should
907
- trap this and quit.
907
+ trap this and quit; alternatively the calling coro should trap and ignore the
908
+ exception. If the exception is not trapped the code will hang: this appears to
909
+ be a bug in ` uasyncio ` V2.0.
908
910
909
911
``` python
910
912
import uasyncio as asyncio
@@ -922,6 +924,27 @@ async def foo():
922
924
await asyncio.wait_for(forever(), 5 )
923
925
await asyncio.sleep(2 )
924
926
927
+ loop = asyncio.get_event_loop()
928
+ loop.run_until_complete(foo())
929
+ ```
930
+ Alternatively:
931
+ ``` python
932
+ import uasyncio as asyncio
933
+
934
+ async def forever ():
935
+ print (' Starting' )
936
+ while True :
937
+ await asyncio.sleep_ms(300 )
938
+ print (' Got here' )
939
+
940
+ async def foo ():
941
+ try :
942
+ await asyncio.wait_for(forever(), 5 )
943
+ except asyncio.TimeoutError:
944
+ pass
945
+ print (' Timeout elapsed.' )
946
+ await asyncio.sleep(2 )
947
+
925
948
loop = asyncio.get_event_loop()
926
949
loop.run_until_complete(foo())
927
950
```
Original file line number Diff line number Diff line change @@ -115,7 +115,6 @@ def __call__(self):
115
115
return self .switchstate
116
116
117
117
async def switchcheck (self ):
118
- loop = asyncio .get_event_loop ()
119
118
while True :
120
119
state = self .pin .value ()
121
120
if state != self .switchstate :
You can’t perform that action at this time.
0 commit comments