Created
October 13, 2022 03:27
-
-
Save ald2004/99053a7ea2c710e0317cd30626cc1874 to your computer and use it in GitHub Desktop.
python process pool executor
This file contains 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 asyncio import as_completed | |
from multiprocessing import Pool | |
import multiprocessing as mp | |
from re import X | |
import re | |
import time | |
import concurrent.futures | |
def xx(a): | |
for _ in range(2): | |
print(f'a:{a}') | |
time.sleep(1) | |
return mp.current_process().name | |
if __name__ == "__main__": | |
a=[1,2,3,4,5,6] | |
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as ex: | |
results=ex.map(xx,a) | |
for i in results: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment