Created
November 5, 2021 13:57
-
-
Save sdtaylor/777b2b559773eb57ae2840e5dcda7908 to your computer and use it in GitHub Desktop.
Basci python multipocessing
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
def processSpecies(speciesName): | |
#do stuff for this species | |
return(result) | |
speciesList=['a','b','c','d'] | |
############################################# | |
#how stuff is typically done | |
results=[] | |
for species in speciesList: | |
results.append(processSpecies(species) | |
############################################ | |
#Or the same thing using a for loop one-liner | |
results=[processSpecies{species) for species in speciesList] | |
############################################ | |
#Same thing as above, but with multi threads | |
import multiprocessing as mp | |
#5 threads | |
p = mp.Pool(5) | |
results=[p.map(processSpecies, speciesList, 2)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment