python_asyncio_course/7_async_constructions/7_1_070_task.py

42 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import asyncio
# База данных
database = [
{"название": "Разработать API", "статус": "Завершена"},
{"название": "Написать документацию", "статус": "Ожидает"},
{"название": "Провести код-ревью", "статус": "Ожидает"},
]
# Не менять
class AsyncListManager:
async def __aenter__(self):
await self.connect()
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.disconnect()
async def connect(self):
print("Начало работы с базой данных")
await asyncio.sleep(0.5)
async def disconnect(self):
print("Завершение работы с базой данных")
await asyncio.sleep(0.5)
async def stage_append(self, value):
await asyncio.sleep(1)
database.append(value)
print("Новые данные добавлены")
# Тут пишите ваш код
async def main():
async with AsyncListManager() as db_manager:
await db_manager.stage_append({'название': 'Настроить CI/CD', 'статус': 'В процессе'})
for db in database:
print(db)
asyncio.run(main())