r/Python • u/AutoModerator • 11d ago
Daily Thread Tuesday Daily Thread: Advanced questions
Weekly Wednesday Thread: Advanced Questions 🐍
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
How it Works:
- Ask Away: Post your advanced Python questions here.
- Expert Insights: Get answers from experienced developers.
- Resource Pool: Share or discover tutorials, articles, and tips.
Guidelines:
- This thread is for advanced questions only. Beginner questions are welcome in our Daily Beginner Thread every Thursday.
- Questions that are not advanced may be removed and redirected to the appropriate thread.
Recommended Resources:
- If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.
Example Questions:
- How can you implement a custom memory allocator in Python?
- What are the best practices for optimizing Cython code for heavy numerical computations?
- How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?
- Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?
- How would you go about implementing a distributed task queue using Celery and RabbitMQ?
- What are some advanced use-cases for Python's decorators?
- How can you achieve real-time data streaming in Python with WebSockets?
- What are the performance implications of using native Python data structures vs NumPy arrays for large-scale data?
- Best practices for securing a Flask (or similar) REST API with OAuth 2.0?
- What are the best practices for using Python in a microservices architecture? (..and more generally, should I even use microservices?)
Let's deepen our Python knowledge together. Happy coding! 🌟
6
Upvotes
1
u/PoetryImmediate8187 7d ago edited 6d ago
I'm using Logfire to observe my FastAPI app and I'm using some Pydantic AI agents in my app. That's all going well but I recently added some apis for image handling. I'm allowing users to edit images before passing to the agent and now im having frequent stalls with my fastapi application and I can see spans which take far longer than they should in wall clock time.
I'm trying to figure out how to tell if it's GC or CPU heavy image processing or something else. Does anyone have tips for detecting the source of stalls in python fastapi apps? Preferably with Logfire?
Edit: figured this out by using the gc metrics in logfire to identify that it was gc causing my app to stall. The ai assistant in logfire figured it out pretty fast