I have this subprocess.Popen()
context manager:
with Popen(
args=command, shell=False, stdout=PIPE, bufsize=1, universal_newlines=True
) as process:
# TIMING
start = timer()
lines = list(process.stdout)
end = timer()
print('Time taken:', end - start) # 53.662078000000065 seconds -> Linux
for _ in tqdm(iterable=lines, total=len(lines)):
sleep(0.1)
if process.returncode != 0:
raise CalledProcessError(returncode=process.returncode, cmd=process.args)
And it seems to take 53 seconds to process list(process.stdout)
when running in a WSL Linux enviorment. However, when I run it in a Windows enviorment, it only takes 0.6 seconds. I'm finding it strange to see why the timings are so different.
I've tried using subprocess.run()
and subprocess.check_output()
instead, but they still lead to the same long lag before processing the tqdm()
loop.
Am I missing something here? I've tried looking at the docs to see what are the differences using subprocess.Popen()
in a Windows vs WSL Linux enviorment, but I'm still unsure what the issue is. Perhaps list(process.stdout)
is unnecessary here, and there is a better way to store the lines from stdout.
Any sort of guidance would be very helpful here.
You will need to reevaluate that performance issue in Q3 2019, with WSL2.
See "Announcing WSL 2" from Craig Loewen
Windows Subsystem for Linux is a bit rubbish. It's got many, many bugs and it's significantly slower than it needs to be. This is just another bug manifesting itself. Here are some possible bottlenecks:
wsl.exe
to launch the program (thanks RoadRunner!)systemd
(?)Deliberate malice on the part of the Windows Subsystem for Linux developers, conspiring to "prove" that Windows is the superior operating system by setting up a strawman.Too silly.There's nothing wrong with your Python code that would make this slow.