<p>此错误消息</p>
<pre><code> File "C:\Users\radus\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 945, in __del__
self._internal_poll(_deadstate=_maxsize)
File "C:\Users\radus\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1344, in _internal_poll
if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] Wrong descriptor
</code></pre>
<p>…表示<code>subprocess.Popen()</code>命令出错</p>
<hr/>
<p>根据<a href="https://github.com/SeleniumHQ/selenium/issues/4505" rel="nofollow noreferrer">Selenium 3.5.0-GeckoDriver 0.18.0-Python 3.6.1 : "OSError: [WinError 6] The handle is invalid" is observed while close() is called through Python PyDev (Eclipse) unittest module</a>中的讨论,即使在通过<em>Python的</em><a href="/questions/tagged/unittest" class="post-tag" title="show questions tagged 'unittest'" rel="tag">unittest</a>模块调用<code>self.driver.close()</code>时也观察到了这个问题</p>
<pre><code>This is because there is no stdin defined in the `service.py` file for the `subprocess.Popen()` command. Underwater the subprocess tries to create a handle which also looks for stdin under Windows this gets a bit tricky when using `Bash` or `cx_Freeze`. So, `stdin` was defined as well, and the crash is gone. Optionally you can also use:
FNULL = open(os.devnull, 'r')
subprocess.Popen(.... ,stdin=FNULL)
</code></pre>
<hr/>
<h2>解决方案</h2>
<p>该解决方案是从<a href="https://github.com/SeleniumHQ/selenium/pull/4503" rel="nofollow noreferrer">Also define stdin or it will crash on Python + cx_Freeze: WindowsErro…</a>拉取请求合并而来的,在<code>Selenium v3.8.1</code>中可用</p>
<p>理想情况下,您需要确保:</p>
<ul>
<li><em>硒</em>被升级到当前水平<a href="https://docs.seleniumhq.org/download/" rel="nofollow noreferrer">Version 3.141.59</a></李>
<li><em>ChromeDriver</em>更新为当前<a href="https://chromedriver.storage.googleapis.com/80.0.3987.16/notes.txt" rel="nofollow noreferrer">ChromeDriver v80.0</a>级别</李>
<li><em>Chrome</em>更新为当前的<em>Chrome 80.0</em>版本。(根据<a href="https://chromedriver.storage.googleapis.com/80.0.3987.16/notes.txt" rel="nofollow noreferrer">ChromeDriver v80.0 release notes</a>)</li>
<li><em>通过<em>IDE</em>清理</em>您的<em>项目工作区</em>,并<em>仅使用所需的依赖项重建</em>项目</李>
<li>始终在<code>tearDown(){}</code>方法中调用<code>driver.quit()</code>以关闭&;优雅地销毁<em>WebDriver</em>和<em>Web客户端</em>实例</李>
</ul>
<hr/>
<h2>tl;博士</h2>
<p><a href="https://bugs.python.org/issue37380" rel="nofollow noreferrer">subprocess.Popen._cleanup() "The handle is invalid" error when some old process is gone</a></p>