Skip to content

Instantly share code, notes, and snippets.

@INF800
Forked from blaylockbk/multipro_template.py
Created March 9, 2022 19:13
Show Gist options
  • Save INF800/7f53226c851cfa854692f0cd3ecfb972 to your computer and use it in GitHub Desktop.
Save INF800/7f53226c851cfa854692f0cd3ecfb972 to your computer and use it in GitHub Desktop.
Template for Python multiprocessing and multithreading
import multiprocessing #:)
def do_this(number):
print number
return number*2
# Create a list to iterate over.
# (Note: Multiprocessing only accepts one item at a time)
some_list = range(0,10)
# Multiprocessing :)
num_proc = multiprocessing.cpu_count() # use all processors
num_proc = 6 # specify number to use (to be nice)
p = multiprocessing.Pool(num_proc)
result = p.map(do_this, some_list)
p.close()
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment