BETTER ASYNC CODE WITH PYTHON 3
Workshop on PyCon.Es, Valencia, 20.11.2015
Contains training tasks for making http requests: first in blocking way, then async using AsyncIO, and finally async using Tornado.
- Task description follows below
- Example solutions are in the
- Feel free to extend, improve, send pull requests
- MIT-licence, everyone is free to reuse this workshop
- Python 3.4.1+
- pyvenv is a good idea
- Write a dummy minimal 'greeting' web-app that waits for one second and sends a greeting (eg Hola, Pycon) to the browser. Use any web-framework you like.
Write a script that requests greeting from ex1 on your local web-server and prints it to shell. Use your favorite blocking http-library - requests, urllib, etc. Request time should result in around 1 second.
Modify your code to call the greeting-server of your neighbour. Delay should be a bit more then 1 second.
Modify your code to get greetings of 3 neighbours in a loop. Since requests are sequential, time would be more then 3 seconds.
1-3. Do same tasks like in Ex.2, but with AsyncIO + aiohttp library.
1-3. Do same tasks like in Ex.2, but with Tornado + tornado AsyncHTTPClient.
Example solutions are in the
Initial tutor/author: Anton