2017-08-07 07:25:35 +00:00
|
|
|
try:
|
|
|
|
import uasyncio as asyncio
|
|
|
|
except:
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
try:
|
|
|
|
import utime as time
|
|
|
|
except:
|
|
|
|
import time
|
|
|
|
|
|
|
|
done = False
|
|
|
|
|
2021-05-27 05:50:04 +00:00
|
|
|
|
2017-08-07 07:25:35 +00:00
|
|
|
async def receiver():
|
|
|
|
global done
|
2021-05-27 05:50:04 +00:00
|
|
|
with open("test_io_starve.py", "rb") as f:
|
2017-08-07 07:25:35 +00:00
|
|
|
sreader = asyncio.StreamReader(f)
|
|
|
|
while True:
|
|
|
|
await asyncio.sleep(0.1)
|
|
|
|
res = await sreader.readline()
|
|
|
|
# Didn't get there with the original problem this test shows
|
|
|
|
done = True
|
|
|
|
|
|
|
|
|
|
|
|
async def foo():
|
|
|
|
start = time.time()
|
|
|
|
while time.time() - start < 1:
|
|
|
|
await asyncio.sleep(0)
|
|
|
|
loop.stop()
|
|
|
|
|
2021-05-27 05:50:04 +00:00
|
|
|
|
2017-08-07 07:25:35 +00:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
loop.create_task(foo())
|
|
|
|
loop.create_task(receiver())
|
|
|
|
loop.run_forever()
|
|
|
|
assert done
|
2021-05-27 05:50:04 +00:00
|
|
|
print("OK")
|