Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiprocess python #5

Open
pestipeti opened this issue Feb 9, 2021 · 0 comments
Open

Multiprocess python #5

pestipeti opened this issue Feb 9, 2021 · 0 comments

Comments

@pestipeti
Copy link

Runs in 3.3077sec, but I also train a CV model, so my machine is a bit busy.

import glob
import time
from multiprocessing import Pool

start = time.time()

files = glob.glob("./data/*.csv")
out = open("out.csv", "w")

def process(idx, src):

    with open(src, 'r') as in_file:

        if idx > 0:
            # Skip the header
            next(in_file)

        for line in in_file:
            out.write(line)


pool = Pool(processes=20)

for idx, f in enumerate(files):

    pool.apply_async(
        process,
        args=(idx, f)
    )

pool.close()
pool.join()
out.close()

end = time.time()
print(end - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant