subprocess.Popen taking too long on WSL Linux

前端 未结 2 1779
广开言路
广开言路 2020-12-11 10:10

I have this subprocess.Popen() context manager:

with Popen(
    args=command, shell=False, stdout=PIPE, bufsize=1, universal_newlines=True
) as process:

            


        
2条回答
  •  不思量自难忘°
    2020-12-11 11:16

    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:

    • Slow context switching in WSL.
    • WSL not noticing that an entire process waiting for a pipe means that the other end of the pipe should be run now.
    • The child process being executed lazily.
    • Windows taking a while to figure out that it needs to use wsl.exe to launch the program (thanks RoadRunner!)
    • The usual overhead of Windows, plus the usual (comparatively small) overhead of Linux.
    • A poor choice of Ubuntu distro causing many unnecessary services to be running in systemd(?)
    • Windows deciding to run other stuff before the child process for some unknown reason.
    • 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.

提交回复
热议问题