close
Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Python subprocess.Popen and asynchronous output

I have simple Python script to execute test suite both under Windows and Linux. Every test writes its output to separate file. I use subprocess.Popen class to execute shell command in a cycle.

Every shell command starts like that:

def system_execute(self, command, path, out_file):
    params_list = command.split(' ') 
    file_path = os.path.join(path, out_file)
    f = open(file_path, "w")
    subprocess.Popen(params_list, stdout=f)
    f.close()

It works fine, but script finishes its work before all output files have been written. Actually, I getting hundreds of zero-size files, and it takes some time to finish writing output and close handles. Could anyone explain the reason why it works so strange, and is there a synchronous way to do the same job?

Thanks

Answer*

Draft saved
Draft discarded

Required fields are marked with *

Cancel
0

lang-py