Skip to content

Commit 24d0a21

Browse files
committed
#15 - Python cambios y correcciones
1 parent 2b2cdc4 commit 24d0a21

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

Roadmap/15 - ASINCRONÍA/python/adra-dev.py

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,48 +40,34 @@
4040
"""
4141

4242
import asyncio
43+
import datetime
4344

4445
"""
4546
Ejercicio
4647
"""
4748

48-
async def hello_world():
49-
print("Name: hello_world")
50-
print("This function will last 3 seconds")
51-
await asyncio.sleep(3)
52-
return print("ends: Hello Wolrd!")
53-
54-
asyncio.run(hello_world())
55-
56-
5749
"""
58-
Extra
50+
Ejercicio
5951
"""
6052

61-
async def A():
62-
await asyncio.sleep(1)
63-
return print("Function A complete")
6453

65-
async def B():
66-
await asyncio.sleep(2)
67-
return print("Function B complete")
54+
async def task(name: str, duration: int):
55+
print(
56+
f"Tarea: {name}. Duración: {duration}s. Inicio: {datetime.datetime.now()}")
57+
await asyncio.sleep(duration)
58+
print(
59+
f"Tarea: {name}. Fin: {datetime.datetime.now()}")
6860

69-
async def C():
70-
await asyncio.sleep(3)
71-
return print("Function C complete")
7261

73-
async def D():
74-
await asyncio.sleep(1)
75-
return print("Function D complete")
62+
asyncio.run(task("1", 2))
7663

77-
async def do_task():
78-
funcC = asyncio.create_task(C())
79-
funcB = asyncio.create_task(B())
80-
funcA = asyncio.create_task(A())
64+
"""
65+
Extra
66+
"""
8167

82-
resultados = await asyncio.gather(funcC, funcB, funcA,)
8368

84-
return resultados
69+
async def async_tasks():
70+
await asyncio.gather(task("C", 3), task("B", 2), task("A", 1))
71+
await task("D", 1)
8572

86-
asyncio.run(do_task())
87-
asyncio.run(D())
73+
asyncio.run(async_tasks())

0 commit comments

Comments
 (0)