擅长:python、mysql、java
<p>从<a href="https://docs.python.org/3/library/subprocess.html" rel="nofollow noreferrer">the ^{<cd1>} documentation</a>:</p>
<blockquote>
<p>If <em>close_fds</em> is true, all file descriptors except <code>0</code>, <code>1</code> and <code>2</code> will be closed before the child process is executed. Otherwise when <em>close_fds</em> is false, file descriptors obey their inheritable flag as described in <a href="https://docs.python.org/3/library/os.html#fd-inheritance" rel="nofollow noreferrer">Inheritance of File Descriptors</a>.</p>
</blockquote>
<blockquote>
<p><em>pass_fds</em> is an optional sequence of file descriptors to keep open between the parent and child.</p>
</blockquote>
<p>要使其工作,请将<code>close_fds=False</code>或<code>pass_fds=[wfd]</code>作为参数添加到<code>subprocess.check_call</code>。快速测试表明,如果您使用<code>pass_fds</code>,则不再需要调用<code>set_inheritable</code>,但如果您使用<code>close_fds</code>,则情况并非如此</p>