Skip to content

appeltel/CoroutineTutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚧 WARNING: THIS REPO IS A HOT MESS - WILL FIX IT UP AFTER I GET HOME! 🚧

A Brief Introduction to Concurrency and Coroutines

This is the repository of links and supporting materials for my PyOhio 2017 tutorial.

Initially I had hoped to provide a full tutorial in written form suitable for studying offline, but that has proven to be too ambitious given the time I have available, so I will be focusing on preparing the live presentation.

Abstract

This is a beginner-friendly introduction to concurrent programming using python coroutines and the standard library asyncio module. The tutorial will first cover the meaning of concurrent programming and how it differs from parallelism. It will then continue to explore the syntax introduced in python 3.5: coroutine definitions, await expressions, async for statements, and async with statements. The need for a framework with a scheduler or event loop will be discussed, with the standard library asyncio package used as an example for the tutorial.

A simple slow web service will be introduced as an example for understanding how to use coroutines. We will write a simple client to make several requests in sequence, and then use the aiohttp library to rewrite it using coroutines to make concurrent requests. Time permitting, we will also look at rewriting the web service itself to use coroutines to handle multiple requests concurrently.

It will be assumed that the listener has a basic understanding of functions, classes, and exceptions in Python, but no prior knowledge of concurrent programming is required.

Setup Instructions

This tutorial requires Python 3.5 or later. You can download the latest version of Python here. I personally use pyenv to manage multiple python versions on my OSX development machine.

In addition to python 3.5 or later, some parts of the tutorial will require the third party packages requests and aiohttp. These can be installed by the commands pip install requests and pip install aiohttp.

I will generally write example code in short modules and then explore using them with python -i module.py. This will run the module and then continue in interactive mode where any functions or classes defined in the module are accessible. These short modules can be found in the examples area of this repository.

Slides as Presented

PDF format slides

Outline

Note: The links in this outline lead to either my own notes for each section or an unfinished draft of the tutorial in written and expanded form.

  1. Warmup: Animals in the Cloud
  2. Cooking with Concurrency
  3. Understanding python Coroutines
  4. Getting to Know asyncio
  5. Animals and aiohttp
  6. Server Side Animals
  7. Publish and Subscribe

About

Coroutine Tutorial in Written Form

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published