Skip to content

Instantly share code, notes, and snippets.

@hahastudio
Last active January 1, 2016 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hahastudio/8177137 to your computer and use it in GitHub Desktop.
Save hahastudio/8177137 to your computer and use it in GitHub Desktop.
from multiprocessing import Pool, cpu_count
from time import sleep
def f(x):
for i in range(10):
print 'counting %d --- Process:%d ' % (i, x)
sleep(1.0+float(x % cpu_count())/5)
def main():
pool = Pool(processes=cpu_count())
for i in range(10):
result = pool.apply_async(f, (i,))
pool.close()
pool.join()
if result.successful():
print 'successful'
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment