concurrent.futures异步任务

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jacke121/article/details/82934480

from concurrent.futures import ThreadPoolExecutor
import time

def wait_on_future():
    f = executor.submit(pow, 5, 2)
    time.sleep(2)
    return (f)


executor = ThreadPoolExecutor(max_workers=2)
future= executor.submit(wait_on_future)
print("222222222222")
try:
    data = future.result()
except Exception as exc:
    print(' generated an exception: %s' % ( exc))
else:
    print(data.result())

猜你喜欢

转载自blog.csdn.net/jacke121/article/details/82934480
今日推荐