import threading
import os
# Normally this would be some busier function... Here it is a stub.
def PlotAlphaMELTS(PathName):
print PathName
# How many threads we want.
NumThreads = 10
# Counter for the thread in the loop.
ThreadCount = 0
# List of the threads.
threads = [None]*NumThreads
# You need a different parameter to each thread to make it do something different.
params = range(100)
# This part is really processor intensive, so let's multithread it.
for p in params:
# Set up a thread.
threads[ThreadCount] = threading.Thread(target=PlotAlphaMELTS, args=(p,))
ThreadCount += 1
# After making NumThreads threads, then we start them all.
if ThreadCount % NumThreads == 0:
for t in threads:
# daemon mode so they run simultaneously.
t.daemon = True
t.start()
# Now they are running. Wait until they all finish.
for t in threads:
t.join()
# And reset the counter so we do a new batch
ThreadCount = 0