Skip to content

Instantly share code, notes, and snippets.

@cgarciae
Last active June 12, 2020 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgarciae/d91e9a54c920cdb9fec326fa5070fa41 to your computer and use it in GitHub Desktop.
Save cgarciae/d91e9a54c920cdb9fec326fa5070fa41 to your computer and use it in GitHub Desktop.
simple pypeln test
import pypeln as pl
import time
from random import random
def slow_add1(x):
time.sleep(random()) # <= some slow computation
return x + 1
def slow_gt3(x):
time.sleep(random()) # <= some slow computation
return x > 3
data = range(10) # [0, 1, 2, ..., 9]
stage = pl.process.map(slow_add1, data, workers=3, maxsize=4)
stage = pl.process.filter(slow_gt3, stage, workers=2)
data = list(stage) # e.g. [5, 6, 9, 4, 8, 10, 7]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment