Change the future

Friday 2:35 p.m.–3:05 p.m.

Using futures for async GUI programming in Python 3.3

Dino Viehland

Audience level:
Intermediate
Category:
Concurrency

Description

In Python 3.2 a new feature was added for concurrent programming - futures. In Python 3.3 generators have been extended to allow returning from a generator with a value. In this talk we'll show how these features can be combined to create a rich and easy to use asynchronous programming model which can be used for creating highly responsive GUI applications or easy async programming.

Abstract

Why async? Blocking creates poor user experiences Avoiding blocking is typically a tedious process Having a common pattern will enable more futures, more concurrent APIs in Python Builds upon standard Python features without adding many new concepts

@async decorator Makes a function automatically return a future instead of a value Generator functions can yield additional futures which are automatically combined

CallableContext Provides the context for how to continue async execution Typically provided by the framework running – e.g. TCL/tk, wxPython, etc…
Callers can capture the current context, and easily post events back to it @async methods automatically continue in the correct context

Demos Conversion of normal future based code to @async
Building new async APIs Updating a UI app to use async features to get rid of blocking