Skip to content

Commit

Permalink
Update a bug with sleep functionality that will affect the asyncio pe…
Browse files Browse the repository at this point in the history
…rformance
  • Loading branch information
ABDreos committed Mar 20, 2024
1 parent f3381a6 commit fce77d4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions 2024/tuesday_tips/testing_async/fetch_event.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import json
import random
from time import sleep
import asyncio

from aiohttp import ClientSession


async def read_data(
path: str = "./data/fictional_events.json",
) -> dict[str, dict[str, str]]:
sleep(random.choice([0.125, 0.5, 0.75, 0.1]))
await asyncio.sleep(random.choice([0.125, 0.5, 0.75, 0.1]))
with open(path) as file:
data = json.load(file)
return data


async def fetch_event(event_id: str, session: ClientSession = None) -> dict[str, str]:
async def fetch_event(
event_id: str, session: ClientSession | None = None
) -> dict[str, str]:
json_data = await read_data()

try:
Expand Down

0 comments on commit fce77d4

Please sign in to comment.