Giter Site home page Giter Site logo

coroutinetutorial's Introduction

๐Ÿšง 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

coroutinetutorial's People

Contributors

appeltel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

coroutinetutorial's Issues

await missing in pubsub_aiohttp.py

In Examples/pubsub_aiohttp.py the line

resp.write(bytes(f'{msg}\r\n', 'utf-8'))

should have an await (resp.write is a coroutine):

await resp.write(bytes(f'{msg}\r\n', 'utf-8'))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.