Skip to content

Instantly share code, notes, and snippets.

@ald2004
Created October 13, 2022 03:27
Show Gist options
  • Save ald2004/99053a7ea2c710e0317cd30626cc1874 to your computer and use it in GitHub Desktop.
Save ald2004/99053a7ea2c710e0317cd30626cc1874 to your computer and use it in GitHub Desktop.
python process pool executor
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