
Django Async & ASGI
ASGI vs WSGI, async views, sync_to_async, async_to_sync, sync ORM limitations, async performance, database connection pooling
1What is the main difference between WSGI and ASGI?
What is the main difference between WSGI and ASGI?
Resposta
ASGI (Asynchronous Server Gateway Interface) extends WSGI by adding support for asynchronous programming and persistent connections like WebSockets. WSGI is synchronous and can only handle one request at a time per worker, while ASGI can handle multiple requests simultaneously in a single process through the asyncio event loop.
2How to declare an async view in Django?
How to declare an async view in Django?
Resposta
An async view in Django is declared simply by using the async keyword before def. Django automatically detects whether the view is asynchronous and runs it in the appropriate event loop. This native Python 3.5+ syntax has been fully supported since Django 3.1.
3What is the role of sync_to_async in Django?
What is the role of sync_to_async in Django?
Resposta
sync_to_async is an adapter provided by asgiref that allows running synchronous code within an asynchronous context. It wraps a synchronous function and executes it in a separate thread pool, preventing blocking of the event loop. This is essential for calling the Django ORM from an async view since the ORM is synchronous.
Why can't the Django ORM be used directly in an async view?
What is the role of async_to_sync in Django?
+23 perguntas de entrevista
Outros temas de entrevista Django
Python Basics
Python OOP
Django Fundamentals
Django Models - Basics
Django Views
Django Templates
Django Forms
Advanced QuerySets
Django Authentication
Django Middleware
Django Admin
Django REST Framework
Django Signals
File Upload
Django Caching
Django Sessions
Django Email
Django Testing
Django Security
Django Deployment
Advanced Django ORM
Django Performance
Django & Celery
Django Channels
Django & GraphQL
Django & Docker
Django in Microservices Ecosystem
Custom Django Commands
Django Internationalization
Django Design Patterns
Settings & Production Configuration
Observability & Monitoring
Domine Django para sua proxima entrevista
Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.
Comece gratis