Look at the count_pairs function. What is its complexity? Write a more efficient version.
Python
FastAPI allows implementing functions as asynchronous and synchronous — how does this affect behavior? How to parallelize requests in an async function?
What is a partition in Kafka? What is a consumer group?
What are the types and kinds of software testing?
Tell me about the Saga pattern. How did you implement it? How did you notify services about the rollback?
What is encapsulation? What are its features from the perspective of Python?
broker = KafkaBroker("localhost:9092") app = FastStream(broker) @broker.subscriber("raw_texts_topic", group_id="text_parsers") async def handle_text(text_data: dict): # Парсинг и сохранение в БД занимает ~10 секунд parse_text_and_save_to_postgres(text_data)
Why is encapsulation necessary? What are the risks of directly accessing an object's data?
Write a Dockerfile for a Python application that does the following: - Uses the latest Python image - Sets the working directory to /app - Copies the current directory contents into the container - Installs the dependencies listed in requirements.txt - Exposes port 8000 - Runs the application using the command: python app.py
# How long does it take for asyncio.run(main()) to execute?
How to create a data structure that cannot have values inserted or modified but can be accessed by key?
How to handle a blocking function from an old library so as not to block the event loop?
async def get_user(user_id: int, db: AsyncSession): try: user = await db.get(User, user_id) return user finally: await db.close() return None a = await get_user(15, db) # a?
app = FastAPI() def get_db(): db = SessionLocal() try: yield db finally: db.close() def heavy_text_parser(file_id: int, db: Session): # Parsing a file that takes 5 minutes parse_and_save(file_id, db) @app.post("/upload") async def upload_file( background_tasks: BackgroundTasks, db: Session = Depends(get_db) ): file_id = save_file_to_db(db) db.commit() background_tasks.add_task(heavy_text_parser, file_id, db) return {"status": "parsing started"}
What is the object returned by a function with `yield`, and what return type annotation is suitable here instead of `list[str]`?
Tell us a little about yourself and your technical experience.
What is the pattern called where `Engine` is created once for the application and manages a shared connection pool?
What happens if the Kafka consumer pod crashes during message processing before committing the offset?
What is REST API?
What are the advantages of a modular monolith compared to microservices in such a situation?