The import of OS, time
The from subprocess import *
The from multiprocessing import *
Def run_shell_cmd (cmd_str index) :
Print (' run shell CMD index % d '% (index,))
Proc=Popen (['/bin/ZSH ', '- c', cmd_str], stdout=PIPE)
Time. Sleep (1)
Outs=proc. Stdout. Readlines ()
Proc. Stdout. Close ()
Proc. The terminate ()
Return
Def multi_process_exc () :
The pool=
Cmd_str='ps - ef | grep chromium'
For the x in the range (5000) : # cycles over a certain number of times will appear the following questions
P=the Process (target=run_shell_cmd, args=(cmd_str, x))
P. tart ()
Pool. Append (p)
For p in the pool:
P.j oin ()
If __name__=="__main__" :
Multi_process_exc ()
Results the following
Process Process - 4078:
Traceback (the most recent call last) :
The File "/usr/lib/python3.8 multiprocessing/process. Py", line 315, in _bootstrap
The self. The run ()
The File "/usr/lib/python3.8 multiprocessing/process. Py", line 108, in the run
Self. _target (, * * * self. _args self. _kwargs)
The File "test. Py", line 8, in run_shell_cmd
Proc=Popen (['/bin/ZSH ', '- c', cmd_str], stdout=PIPE)
The File "/usr/lib/python3.8 subprocess. Py", line 854, in __init__
Self. _execute_child (args, the executable, preexec_fn close_fds,
The File "/usr/lib/python3.8 subprocess. Py", line 1603, in _execute_child
Errpipe_read, errpipe_write=OS. Pipe ()
OSError: [24] Errno Too many open files
The system environment:
Linux DJ 5.4.28 # 1-1 - MANJARO SMP PREEMPT Wed Mar 25 12:45:29 UTC 2020 x86_64 GNU/Linux
Python3.8
CodePudding user response:
Oneself the top, a real environment is the child will perform a shell command reads all current processes,Process open too much if it exceeds the system limit, lsof to view a large number of PIPE is not closed, tried various methods to also won't shut down, I don't know what a great god help below the answer