Last active
June 12, 2020 14:34
-
-
Save cgarciae/d91e9a54c920cdb9fec326fa5070fa41 to your computer and use it in GitHub Desktop.
simple pypeln test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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