File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """Interact with a running event loop."""
12import asyncio
23
34from asyncio_tutorial .logger import LOGGER
45
56
67def inspect_event_loop ():
7- """Get event loop info ."""
8+ """Inspect metadata for the current running event loop."""
89 loop = asyncio .get_event_loop ()
910 thread_id = loop .__dict__ .get ("_thread_id" )
1011 if loop .is_running ():
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ async def create_tasks(
1212 session : ClientSession , urls : List [str ], directory
1313) -> List [Task ]:
1414 """
15- Create asyncio tasks to be executed .
15+ Create asyncio tasks to be execute the `fetch_and_save_url` coroutinne .
1616
1717 :param ClientSession session: Async HTTP requests session.
1818 :param List[str] urls: Resource URLs to fetch.
Original file line number Diff line number Diff line change 1- """Simple script to create and execute tasks in a loop"""
1+ """Create and execute asynchronous tasks in a loop. """
22import asyncio
33
44from asyncio_tutorial .logger import LOGGER
1010
1111
1212async def asyncio_intro_tutorial ():
13- """Simple demonstration of a async script lifecycle"""
13+ """Demo of an asynchronous script's lifecycle. """
1414 LOGGER .info (f"Asyncio tutorial Part I: Intro to Asyncio." )
1515 tasks = []
1616 future = register_future ()
Original file line number Diff line number Diff line change 1- """Create a coroutine containing the business logic of our task."""
1+ """Create a coroutine function to be executed as asyncio task."""
22import asyncio
33
44from asyncio_tutorial .logger import LOGGER
55
66
77async def simple_coroutine (number : int , delay = 1 ):
88 """
9- Wait for a time delay, log number associated with the coroutine.
9+ Wait for a time delay & display number associated with coroutine.
1010
1111 :param int number: Number to identify the current coroutine.
12- :param int delay: Time delay to simulate a function which takes time to complete .
12+ :param int delay: Time delay to simulate function delay .
1313 """
1414 await asyncio .sleep (delay )
1515 LOGGER .info (f"This is Coroutine { number } being executed." )
Original file line number Diff line number Diff line change 1- """Create a Future (callback): an action to be taken when loop is completed."""
1+ """Future which executes an action when loop is completed."""
22import asyncio
33from asyncio import Future
44
77
88def register_future () -> Future :
99 """
10- Create a Future to log when loop is completed.
10+ Create a Future which triggers a callback when loop is completed.
1111
1212 :returns: Future
1313 """
@@ -19,11 +19,11 @@ def register_future() -> Future:
1919
2020def loop_completed (result : str ):
2121 """
22- Callback to be called when loop is complete.
22+ Callback function fired when loop is complete.
2323
24- :param str result: Simple string describing the state of the loop
24+ :param str result: String describing the state of the loop
2525 """
2626 LOGGER .success (
2727 f"Loop completed with result: { result } \
28- \n ----------- --------------------------------------"
28+ \n --------------------------------------"
2929 )
Original file line number Diff line number Diff line change 1+ """Interact with a running event loop."""
12import asyncio
23
34from asyncio_tutorial .logger import LOGGER
45
56
67def inspect_event_loop ():
7- """Get event loop info ."""
8+ """Inspect metadata for the current running event loop."""
89 loop = asyncio .get_event_loop ()
910 thread_id = loop .__dict__ .get ("_thread_id" )
1011 if loop .is_running ():
Original file line number Diff line number Diff line change 1- """Create task from provided coroutine."""
1+ """Create task from coroutine which displays a value after a delay ."""
22import asyncio
33from asyncio import Task
44
You can’t perform that action at this time.
0 commit comments