Last active
July 5, 2017 17:04
-
-
Save daidokoro/11eade070259b0314a080644b171a819 to your computer and use it in GitHub Desktop.
concurrent_futures_example
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
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