* * Python Training Classes - In Chicago * *

with David Beazley
Author of the "Python Essential Reference"
Dabeaz LLC
5412 N Clark Street #218
Chicago, IL 60640

Target Audience [ Advanced ]

This course is for more experienced Python programmers who like a challenge and who want to take their Python skills to a whole new level. Attendees are expected to already be familiar with the core Python language and common library modules such as pickle, os, sys, etc. Having some basic knowledge of network and systems programming is advised.

Price: $595 (Regular), $125 (Student)

[Register | More Information | FAQ]

Python Concurrency Workshop

January 17, 2010. Update! The January, 2010 workshop was a success. Look for another offering in the Summer.

This one-of-kind workshop, designed for more experienced Python programmers, provides an in-depth examination of concurrent programming idioms and standard library modules. The aim of this workshop is to go far beyond the information found in the manual and to gain a deeper understanding of how different approaches work, their performance characteristics, limitations, and types of real-world problems for which they are suited. Course topics include, but are not limited to the following:

  • Interpreter execution model
  • Thread programming
  • The global interpreter lock
  • Subprocesses
  • Multiprocessing
  • Interprocess communication
  • Message queues and message passing
  • Coroutines
  • Asynchronous and non-blocking I/O
  • Distributed computing

Workshop Agenda

Here is a outline for the workshop.

  1. Thread Programming. Everything you wanted to know about Python threads, but were afraid to ask. Includes the absolute basics of using the threading module and different techniques for using threads to carry out work. Includes detailed coverage of using different synchronization primitives, queues, and thread pools. Also provided detailed information on the Global Interpreter Lock (GIL), tuning parameters, and the interaction between threads and C/C++ extension modules.
  2. Message Passing and Data Serialization. Message passing is a core component of distributed computation. This section provides an in-depth look at different interprocess communication mechanisms, their performance characteristics, and tuning options. In addition, different approaches for serializing Python data structures are explored. Topics include the subprocess module, named pipes, network sockets, memory mapped regions, pickle, marshal, structure packing, and binary I/O.
  3. Multiprocessing. A tour of features provided by the multiprocessing library added in Python 2.6. Covers processes, queues, pipes, process pools, and shared memory regions. Examples will illustrate how multiprocessing can be used to achieve higher performance when working on multiple CPU cores.
  4. Distributed Programming. An in-depth tour of different distributed programming techniques. Topics include programming with actors, client-server computing, REST, remote procedure call, and distributed objects. Also includes material on XML-RPC and WSGI.
  5. Advanced I/O handling. A look at different I/O handling techniques including blocking, non-blocking, asynchronous, and event-driven I/O. The primary goal of this section is to better understand the I/O handling using by different libraries and frameworks such as asyncore, Twisted, etc.

  6. Generators and Coroutines. An overview of concurrent programming using generators and coroutines. The major focus of this section is on using generators to implement user-level task switching and to better understand libraries based on microthreads, tasklets, green-threads, and similarly named entities.

Format

The workshop consists of highly detailed presentation slides and nearly 50 hands on exercises where you will get to experiment--approximately half the time will be spent working on programs. For a sample of presentation materials, see my talk on the Python GIL. If you are familiar with some of my past PyCON tutorials, you should know that the concurrency workshop has almost no overlap. With the exception of the GIL talk, almost all of the material has not been presented in any other venue.

Visit Chicago in January? Are you kidding?

January is a great time to visit Chicago when airfares and hotels are cheap and available. Besides, we're going to spend the whole time inside hacking code. I will just mention that the workshop venue is just steps away from about about a dozen bakeries and coffee shops, not to mention Chicago's most famous pub for getting strong Belgian ales. Staying warm will be the least of your concerns. That said, you should still bring a good coat though :-).

Slide Topic Index

The following table, generated automatically from the workshop presentation slides, gives much more detail about the material to be covered. This outline is still subject to minor changes as the workshop nears.

1. Introduction

Python Concurrency Workshop1-1
Welcome!1-2
Requirements1-3
Concurrency1-4
A Warning1-6
Basic Concurrency Concepts1-7
Concurrent Programming1-8
Multitasking1-9
Parallel Processing1-10
Task Execution1-11
CPU Bound Tasks1-12
I/O Bound Tasks1-13
Shared Memory1-14
Processes 1-15
Distributed Computing1-16
Why Python?1-17
Some Issues1-18
Why Use Python at All?1-19
Python as a Framework1-20
Programming Productivity1-21
Performance is Irrelevant1-22
You Can Go Faster1-23
Commentary1-24
Let's Get Started1-25

2. Thread Programming

Python Multithreading2-1
Overview2-2
Background : Threads2-3
Usage : Threads2-4
Concept: Threads2-5
Thread Basics2-6
threading Module2-11
Thread Objects2-12
Launching Thread Objects2-13
Thread Execution2-14
Joining a Thread2-15
Thread Status2-16
Interpreter Execution2-17
Daemonic Threads2-18
Keyboard Interrupt2-19
Killing Threads2-20
Thread Termination2-21
Returning Results2-23
The Problem2-24
Returning Results2-25
Result Objects2-26
Returning Results2-27
Returning Exceptions2-28
Results w/ Exceptions2-29
Returning Exceptions2-30
An Exception Wart2-31
Commentary2-34
Threads and Memory2-36
Shared Memory2-37
Shared Objects2-38
Thread Local Data2-39
Interlude2-42
Debugging with Threads2-43
Setting the Thread Name2-44
Thread Logging2-45
Logging Information2-46
Nondeterminism2-48
Accessing Shared Data2-49
Race Conditions2-53
Thread Synchronization2-54
Synchronization Options2-55
Mutex Locks2-57
Use of Mutex Locks2-59
Using a Mutex Lock2-60
Locking Perils2-63
Lock Management2-64
Locks and Deadlock2-66
Special Topic:2-68
with Statement2-69
Context Management2-70
Context Mgr: Locking2-72
Exception Handling2-73
Context Setup2-74
A Simple Example2-75
Where to Put Locks?2-77
Fine-Grained Locking2-78
Locking Costs2-79
Contested Locking2-80
Course-Grained Locking2-81
RLock2-82
RLock Example2-83
Commentary2-84
Special Topic:2-85
Background2-86
Decorators2-87
A Decorator for Locking2-88
Discussion2-89
An Example2-90
Decorators with Arguments2-91
Semaphores2-94
Semaphore Uses2-95
Resource Control2-96
Thread Signaling2-97
Events2-100
Barrier Synchronization2-101
Event Waiting2-102
Condition Variables2-104
Interlude2-109
Threads and Queues2-110
Queue Library Module2-111
Queue Usage2-112
Queue Completion2-113
Queue Programming2-114
Example: Thread Pools2-115
An Inconvenient Truth2-117
A Performance Test2-118
Bizarre Results2-119
Interlude2-121
What is a Thread?2-122
Thread Creation2-123
Behind the Scenes2-124
Thread-Specific State2-125
PyThreadState Structure2-126
Threads and sys module2-127
Thread Execution2-128
The Infamous GIL2-129
GIL Behavior2-130
CPU Bound Processing2-131
The Check Interval2-132
The Periodic Check2-133
What is a "Tick?"2-134
Tick Execution2-135
Interlude : Signals2-136
Signal Handling2-137
Thread Scheduling2-138
Frozen Signals2-139
A Useful Tip2-140
GIL Implementation2-142
Thread Scheduling2-143
CPU-Bound Threads2-144
Signaling Overhead2-145
A Rough Measurement2-146
Multiple CPU Cores2-147
Multicore GIL Contention2-148
The GIL and C Code2-150
The GIL and C Extensions2-151
How to Release the GIL2-152
The GIL and C Extensions2-153
Why is the GIL there?2-157
GIL Future2-158
A Note on Locks2-159
Some Lessons Learned2-160
Using Threads2-161
I/O Bound Processing2-162
Thread Limits2-164
Check Interval Tuning2-165
Cooperative Multitasking2-166
Thread Memory Use2-167
Thread Stack Space2-168
Final Comments2-169

3. Messaging and Data Serialization

Message Passing3-1
Concept: Message Passing3-2
Commentary3-3
Message Passing3-4
Problem Decomposition3-5
Example : Dataflow3-6
Example : Worker Pool3-8
Example : Map-Reduce3-10
Example : Decomposed Data3-11
Comments3-13
Sending Messages3-14
A Problem3-15
Section Focus3-16
Some Tricky Bits3-17
Preview3-18
Messaging Basics3-19
What is a Message?3-20
Message Transport3-21
Pipes3-22
An Example3-23
Named Pipes/FIFOs3-24
Pipe Performance3-25
Sockets3-26
Using Sockets3-27
Socket Families3-28
Datagrams3-29
Datagram Example3-30
Memory Mapped Regions3-32
Using mmap3-34
Data Overlay3-35
mmap Commentary3-36
Message Encoding3-38
Some Philosophy3-39
Object Serialization3-40
The Problem3-41
pickle Module3-42
Some Pickle Issues3-45
cPickle vs. Pickle3-46
Pickle Encodings3-48
Selecting a Protocol3-49
Pickling to Strings3-52
Pickling Instances3-53
Python and References3-55
Reference Example3-56
Pickle and References3-57
Preserving References3-59
Pickler Objects3-60
Pickler Caution3-61
Pickle and Large Objects3-62
Classes and Functions3-63
Miscellaneous Comments3-64
marshal Module3-66
Foreign Objects3-69
struct module3-70
Structure Alignment3-74
Packing Binary Records3-75
Unpacking Records3-76
Performance Tip3-77
struct Comments3-78
struct Cautions3-79
Binary Arrays3-81
ByteArray Objects3-82
Direct Array Output3-83
Direct Array Input3-84
Direct Array Overwriting3-86
ctypes module3-88
ctypes Types3-89
ctypes module3-90
ctypes arrays3-91
ctypes module3-92
ctypes Caution3-94
buffer() function3-96
buffer() Function3-97
Using buffer()3-98
Recognizing Buffers3-101
Messaging Wrap up3-103

4. Multiprocessing

Multiprocessing4-1
multiprocessing Module4-2
Multiprocessing Tour4-4
Processes4-5
Functions as Processes4-6
multiprocessing Example4-7
Launching Processes4-8
Does it Work?4-9
Other Process Features4-10
Process Creation4-11
A Caution4-12
Distributed Memory4-15
Synchronization Primitives4-16
Message Queues4-17
Joinable Queues4-18
Queue Example4-19
Commentary4-21
Pipes4-23
Using Pipes4-24
Pipe Setup4-25
Advice4-26
Pipe Example4-27
Pipes vs. Queues4-29
Process Pools4-31
Async Results4-35
Process Pools4-36
Using Process Pools4-38
Shared Data4-40
Shared Example4-41
Shared Arrays4-42
Locking Performance4-43
Lock-Free Sharing4-44
Wrap Up4-45

5. Distributed Programming

Distributed Programming5-1
Introduction5-2
A Problem5-3
Commentary5-4
Silver Bullets5-5
Overview5-6
Major Topics5-7
Actor Programming5-8
Actors5-9
Features of Actors5-10
Actor History5-11
Disclosure5-12
Actor Implementation5-13
An Example5-14
Another Example5-15
Using Actors5-16
A Problem5-18
Actor Runtime5-19
Async Messaging5-20
Concurrency5-21
Implementing the Runtime5-22
Example: Threaded Actor5-23
Actors and Processes5-29
Process Issues5-30
Actor Addressing5-32
Actor Naming5-33
Names and Wrappers5-36
Name Registry5-38
Message Addressing5-40
Implementing send()5-41
Examples5-42
Distributed Actors5-44
Connection Objects5-45
Distributed Send5-49
Proxy Actors5-50
Proxy Implementation5-51
Using a Proxy5-52
Message Dispatching5-53
Message Dispatcher5-54
Using the Dispatcher5-59
Putting it All Together5-60
Big Picture5-61
Tricky Bits With Actors5-63
What's in a Message?5-64
Instances and Messages5-65
Don't Do It!5-69
Actor Naming5-70
Name Registry5-71
Registry Details5-72
Concurrency Alternatives5-73
Optional Concurrency5-74
Concurrency Alternatives5-76
Hard Problems5-77
Actor Commentary5-79
A Caution5-80
Client/Server Computing5-81
Client/Server Comments5-83
RESTful Services5-84
REST Resources5-85
Resource Representation5-86
REST Actions5-87
REST Examples5-88
Stateless Implementation5-90
Reuse of HTTP5-91
Implementing REST5-92
Example with WSGI5-93
Running an WSGI App5-98
RESTful WSGI5-100
REST Example5-101
Running the Server5-105
REST Clients5-106
REST Commentary5-109
Remote Procedure Call5-112
XML-RPC5-115
Simple XML-RPC5-116
XML-RPC Commentary5-118
XML-RPC and Binary5-119
XML-RPC and Instances5-120
Some Issues5-121
More Commentary5-122
RPC Libraries5-123
Problems with Objects5-125
Distributed Objects5-126
Server Instances5-128
Server Dispatching5-129
Client Proxies5-130
Object Registry5-131
Proxy Creation/Lookup5-132
Various Problems5-134
Object Managers5-135
Managers5-136
Using a Manager5-137
Manager Example5-138
Commentary5-143
Hard Problems5-144
Some Resources5-145
Resources5-146
Final Comments5-147

6. Advanced I/O

Advanced I/O Handling6-1
Introduction6-2
Disclaimers6-3
Goal6-4
I/O Basics6-5
Blocking I/O6-6
Blocking I/O Rules6-9
Caution : Partial Sends6-10
Socket Tuning Parameters6-11
Non-blocking I/O6-13
Non-blocking Sockets6-14
Using Non-blocking I/O6-15
Overlapped I/O6-16
Overlapped I/O Example6-17
Commentary6-18
Asynchronous I/O6-20
Signal Driven I/O6-22
Commentary6-24
I/O Polling/Multiplexing6-25
select module6-26
select() function6-27
select() performance6-30
A select() limitation6-32
Event Driven I/O6-34
Event Driven "Tasks"6-37
Multitasking6-40
Example : Time Server6-41
A Complication6-44
Solution6-45
Example : Echo Server6-46
Commentary6-51
Events and Asyncore6-52
Using Asyncore6-53
Twisted6-54
Twisted Example6-55
Event Driven Problems6-56
Scaling Problems6-57
Some Solutions6-59
A Scaling Benefit6-60
Long-Running Calculations6-61
Blocking Operations6-62
The Blocking Problem6-63
Incremental Feeding6-65
Events and Threads6-66
Interoperability Problems6-68
Personal Bias6-69
Commentary6-70

7. Generators and Coroutines

Generators and Coroutines7-1
Introduction7-2
Reference Material7-3
Background Material7-4
Generators7-5
Generator Functions7-7
A Practical Example7-9
Generators as Pipelines7-10
A Pipeline Example7-11
Yield as an Expression7-12
Coroutines7-13
Coroutine Execution7-14
Coroutine Priming7-15
Using a Decorator7-16
Processing Pipelines7-17
An Example7-18
Generators as Tasks7-21
Program Execution7-22
Task Switching7-23
An Insight7-24
Multitasking Example7-25
Scheduling Example7-26
Yielding For I/O7-29
More About Yield7-30
Talking to the Scheduler7-31
An Example Task7-32
Signaling an I/O Request7-33
Implementing I/O Waits7-35
Building a Scheduler7-36
Example : Time Server7-44
Example : Echo Server7-45
Comments7-48
Problems7-50
Some Links7-52
More Information7-53
Copyright (C) 2009-2010, Dabeaz LLC. All Rights Reserved.