Skip to content

Commit 60f4e82

Browse files
committed
Refactor.
1 parent 68e88b4 commit 60f4e82

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

asyncio_tutorial/__init__.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Script initialization."""
22
import asyncio
3-
from asyncio import SelectorEventLoop, Task
4-
from typing import List
53

64
from aiohttp import ClientSession
75

@@ -19,20 +17,19 @@ async def init_script():
1917
async with ClientSession(headers=HTML_HEADERS) as session:
2018
tasks = await create_tasks(session, urls, HTML_EXPORT_DIR)
2119
await asyncio.gather(*tasks)
22-
loop = inspect_loop(tasks)
20+
loop_status = await inspect_loop()
2321
LOGGER.success(
24-
f"Saved {len(urls)} HTML pages to `{HTML_EXPORT_DIR}`. Loop: {loop}"
22+
f"Saved {len(urls)} HTML pages to `{HTML_EXPORT_DIR}`. {loop_status}"
2523
)
2624

2725

28-
def inspect_loop(tasks: List[Task]) -> SelectorEventLoop:
26+
async def inspect_loop() -> str:
2927
"""
30-
Get async loop info.
28+
Get event loop info.
3129
3230
:param: List[Task] tasks
3331
34-
:return: SelectorEventLoop
32+
:return: str
3533
"""
36-
loop = tasks[0].get_loop()
37-
LOGGER.info(f"Loop info: {loop}")
38-
return loop
34+
loop = asyncio.get_event_loop()
35+
return f"Loop finished in {loop.time()} seconds."

0 commit comments

Comments
 (0)