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

PyType does not support running in parallel? #1623

Closed
YingboFu opened this issue May 19, 2024 · 1 comment
Closed

PyType does not support running in parallel? #1623

YingboFu opened this issue May 19, 2024 · 1 comment

Comments

@YingboFu
Copy link
Contributor

Hi, thanks a lot for developing the amazing PyType!

I currently have thousands of Python files to run PyType on, which will take months. Thus, I'd like to run PyType on those files in parallel. However, I've tried both Python multiprocessing and GNU parallel, and neither of them works.

Suppose we have three python files <a.py, b.py, c.py> and I'd like to use three processors of my machine and each processor run PyType on one different file (i.e. one runs pytype a.py, one runs pytype b.py and one runs pytype c.py). I've tried the following Python script:

import multiprocessing
import subprocess
import os

def work(cmd):
    result = subprocess.run(cmd, capture_output=True, text=True)
    return f"{os.getpid()} - Command: {cmd}\nOutput: {result.stdout}\nError: {result.stderr}"


if __name__ == '__main__':
    files = ["a.py", "b.py", "c.py"]
    cmds = []
    for file in files:
        cmds.append(["pytype", file])
    count = multiprocessing.cpu_count()
    with multiprocessing.Pool(processes=count) as pool:
        results = pool.map(work, cmds)
    for result in results:
        print(result)

However, the results show that all processors run Pytype on the same file.

Then, I tried GNU parallel:

parallel -j 3 pytype {} ::: a.py b.py c.py

It gives the same results that all processors actually run Pytype on the same file.

Thus, is this because PyType internally does not allow running in parallel?

Thanks a lot for your help!

@h-joo
Copy link
Contributor

h-joo commented May 20, 2024

Hi, may I ask how the three different input files look like? Are they co-dependent? (does one import another)
Can you also elaborate on what you mean by "However, the results show that all processors run Pytype on the same file."

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

2 participants