Skip to content

Instantly share code, notes, and snippets.

@sdtaylor
Created November 5, 2021 13:57
Show Gist options
  • Save sdtaylor/777b2b559773eb57ae2840e5dcda7908 to your computer and use it in GitHub Desktop.
Save sdtaylor/777b2b559773eb57ae2840e5dcda7908 to your computer and use it in GitHub Desktop.
Basci python multipocessing
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