43 lines
736 B
Python
43 lines
736 B
Python
|
|
import asyncio
|
|
import random
|
|
import logging
|
|
|
|
# Logging konfigurieren
|
|
logging.basicConfig(
|
|
filename="begrüssung.log",
|
|
filemode="w",
|
|
level=logging.INFO,
|
|
format="%(asctime)s - %(message)s"
|
|
)
|
|
|
|
|
|
# Coroutine für eine Begrüßung
|
|
async def greet(name):
|
|
|
|
logging.info(f"Start der Begrüßung für {name}")
|
|
|
|
# Zufällige Wartezeit zwischen 1 und 3 Sekunden
|
|
wartezeit = random.randint(1, 3)
|
|
|
|
await asyncio.sleep(wartezeit)
|
|
|
|
# Begrüßung ausgeben
|
|
print(f"Hallo {name}!")
|
|
|
|
logging.info(f"Ende der Begrüßung für {name}")
|
|
|
|
|
|
# Hauptprogramm
|
|
async def main():
|
|
|
|
await asyncio.gather(
|
|
greet("Anna"),
|
|
greet("Max"),
|
|
greet("Lisa")
|
|
)
|
|
|
|
|
|
# Programm starten
|
|
asyncio.run(main())
|