Skip to content

Instantly share code, notes, and snippets.

@leopard627
Created November 15, 2020 12:12
Show Gist options
  • Save leopard627/cd563f1d579ad497ef6aab23697684bf to your computer and use it in GitHub Desktop.
Save leopard627/cd563f1d579ad497ef6aab23697684bf to your computer and use it in GitHub Desktop.
asyicIO with django view
import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
def send_email_with_asyncio(user, email):
# email sending logic
# .........................
# .................................
class DummyViewSet(DeleteMixin, viewsets.ModelViewSet):
def send_email_auth(self, request):
# ......................
loop.run_in_executor(
None, send_email_with_asyncio, [user, email])
#
return Response({"results": "So!! Fast!!"}, status=status.HTTP_200_OK)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment