Title: Concurrent Processing
Slug: concurrent_processing
Summary: Concurrent Processing in Python.
Date: 2016-01-23 12:00
Category: Python
Tags: Basics
Authors: Chris Albon
Interesting in learning more? Check out Fluent Python
In [1]:
from concurrent import futures
In [2]:
data = range(100)
In [3]:
# Create some function that takes a value
def some_function(value):
# And outputs it raised to its own power
return value**value
In [4]:
# With a pool of workers
with futures.ProcessPoolExecutor() as executor:
# Map the function to the data
result = executor.map(some_function, data)
In [5]:
# List the first 5 outputs
list(result)[0:5]
Out[5]: