Created
November 15, 2020 12:12
-
-
Save leopard627/cd563f1d579ad497ef6aab23697684bf to your computer and use it in GitHub Desktop.
asyicIO with django view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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