使用https://pypi.org/project/cproto/,附加到在 Docker 容器中无头运行的 Chrome 上,我发现它有时会卡住(下面引用的示例不可靠 - 您可能需要运行它几次):
$ python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cproto
>>> cp = cproto.CProto() # localhost:9222 == my Chrome container
>>> cp.close()
>>> exit()
^CException ignored in: <module 'threading' from '/usr/lib/python3.6/threading.py'>
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 1294, in _shutdown
t.join()
File "/usr/lib/python3.6/threading.py", line 1056, in join
self._wait_for_tstate_lock()
File "/usr/lib/python3.6/threading.py", line 1072, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt
$
这也发生在 Chrome 正常运行时,带有一个 UI,在 Docker 之外。
不管 Chrome 可能会处理什么讨厌的事情,cproto 库应该像这样陷入困境似乎有点“离题”。
有没有办法强制退出cproto? (我在上面做错了什么,还是这是一个错误?)