Created
March 9, 2013 19:07
-
-
Save robertklep/5125319 to your computer and use it in GitHub Desktop.
multiprocessing pool test
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
#!/usr/bin/env python | |
import multiprocessing, sys, random, time | |
def process_file(filename, foo, bar, baz='biz'): | |
print "FOO" | |
if random.random() < 0.5: | |
raise Exception("blah") | |
return 123 | |
if __name__ == '__main__': | |
# setup code setting parameters foo, bar, and biz | |
psize = 4 # multiprocessing.cpu_count()*2 | |
pool = multiprocessing.Pool(processes=psize) | |
a = map(lambda x: pool.apply_async(process_file, (x, 'foo', 'bar'), dict(baz='biz')), sys.argv[1:]) | |
pool.close() | |
pool.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment