When using subprocess to execute a series of CMD commands in Python, occasionally there will be blocking, and the command does not continue to execute.
reason:
The pipe of a subprocess has a size. Before python2.6.11, the size of pipe was the size of file page (4096 on i386),
# after 2.6.11, it became 65536. Therefore, when the output content exceeded 65536, it would cause blocking
solve:
1. Use tempfile to expand the cache;
2. Remove unnecessary output to reduce the output
In scheme 1, the temporary file tempfile is used to expand the cache
out_ temp = tempfile.SpooledTemporaryFile (bufsize=10 * 1000)
fileno = out_ temp.fileno ()
process = subprocess.Popen (cmd, stdout=fileno, stderr=fileno, shell=True) # stdout= subprocess.PIPE ,
Scheme 2, according to the actual situation to reduce unnecessary data.
Read More:
- Command line is too long. Shorten command line for QuestionnaireApplication or also for Spring Boot
- Error running ‘application’: command line is too long. Short command line for application
- Python packaged *. Exe is running os.popen (cmd)/ subprocess.Popen *. Exe crashes with invalid [winerror 6] handle
- FTP use get command 550 failed to open file, but use the put command to solve the problem
- Solution to command line option syntax error. Type command /? For help
- Error command line is too long when idea project is started [How to Solve]
- Idea Startup Error: Command line is too long [How to Solve]
- Idea running error running ‘application’: solution to command line is too long
- 1. Error running ‘application’ occurs when the command line is too long
- Idea: error running Name: command line is too long
- Error running ‘SpringCloudStarter‘: Command line is too long. Shorten comman
- Error in idea unit test command line is too long
- [Solved] VUE Error: “You may use special comments to disable some warnings.Use // eslint-disable-next-line to …
- Xcode: error: linker command failed with exit code 1(use -v to see invocation) or libstdc++.6.0 is missing
- The python version output from the command line is inconsistent with the python version in the current CONDA environment
- Slim error “failed to execute login command”
- How to terminate the current program under linux command line?
- SVN: Please execute the ‘Cleanup‘ command.
- Solve the problem of error running xxxapplication command line is too long when compiling and running IntelliJ idea