Created
August 27, 2011 14:07
-
-
Save xulapp/1175426 to your computer and use it in GitHub Desktop.
parallel
This file contains hidden or 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 parallel(tasks): | |
from threading import Thread | |
def target(i, task): | |
results[i] = task() | |
threads = [Thread(target=target, args=args) for args in enumerate(tasks)] | |
results = [None] * len(tasks) | |
for thread in threads: | |
thread.start() | |
for thread in threads: | |
thread.join() | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment