I'm trying to test if I'm correctly using an asyncio library (aiofiles) to see if its blocking.
How can I do this? My idea was to have an infinite loop of asyncio.sleep checking the delay between each call, while I try to insert a blocking call in between
This is my current try, but blocking is never called, I'm assuming the problem is that the infinite loop is actually also blocking.
from asyncio import sleep, get_event_loop
import time
async def test_blocking():
while True:
timea = time.time()
await sleep(1)
timeb = time.time() - timea
delay = timeb - 1.00
if delay >= 0.01:
print(f'Function blocked by {delay}s')
async def blocking():
print('Running blocking function')
time.sleep(5)
loop = get_event_loop()
loop.run_until_complete(test_blocking())
loop.run_until_complete(blocking())