Created
October 30, 2015 18:30
-
-
Save wbbradley/e91fdc02edfe25c2cf93 to your computer and use it in GitHub Desktop.
Easy async processing in Python
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 uuid | |
from multiprocessing import Pool | |
def f(u): | |
print str(u) + ' is a uuid' | |
if __name__ == '__main__': | |
pool = Pool(processes=2) | |
# get some random uuids | |
uuids = [uuid.uuid4() for x in range(10)] | |
for u in uuids: | |
# enqueue a new async task | |
pool.apply_async(f, [u]) | |
pool.close() | |
pool.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment