Skip to content

Instantly share code, notes, and snippets.

@yeondudad
Last active August 29, 2015 14:14
Show Gist options
  • Save yeondudad/e02fb2f023a373d21291 to your computer and use it in GitHub Desktop.
Save yeondudad/e02fb2f023a373d21291 to your computer and use it in GitHub Desktop.
from multiprocessing.pool import ThreadPool
from os import getpid
from time import sleep
def fn_sleep(s):
sleep(s)
return getpid()
sleep_time = [10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
pool = ThreadPool()
async_results = []
for s_ in sleep_time:
async_result = pool.apply_async(fn_sleep, kwds={'s': s_})
async_results.append(async_result)
print [async_result.get() for async_result in async_results]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment