Created
April 26, 2013 19:03
-
-
Save 89465127/5469584 to your computer and use it in GitHub Desktop.
Multiprocessing example, iterating over each line in a file.
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
import multiprocessing | |
import StringIO | |
# function to be run on each line of file | |
def f(x): | |
print x, | |
# Create mock file | |
mock_file = StringIO.StringIO() | |
for i in range(20): | |
mock_file.write("{}\n".format(i)) | |
mock_file.seek(0) | |
# run it! | |
pool = multiprocessing.Pool(processes=4) | |
pool.map(f, mock_file) | |
# Cleanup | |
mock_file.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment