Skip to content

Instantly share code, notes, and snippets.

@daidokoro
Last active July 5, 2017 17:04
Show Gist options
  • Save daidokoro/11eade070259b0314a080644b171a819 to your computer and use it in GitHub Desktop.
Save daidokoro/11eade070259b0314a080644b171a819 to your computer and use it in GitHub Desktop.
concurrent_futures_example
from concurrent.futures import ThreadPoolExecutor, as_completed
import time, random
class Jobs(object):
# create queue
queue = ThreadPoolExecutor(max_workers=4)
jobs = []
@staticmethod
def add_job(func, *args):
Jobs.jobs.append(Jobs.queue.submit(func, *args))
@staticmethod
def get_response():
for item in as_completed(Jobs.jobs):
print(item.result())
def dummy(num):
time.sleep(num)
return True, num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment