Python pypi cproto(chrome调试客户端)在退出时挂起

Python pypi cproto(chrome调试客户端)在退出时挂起,python,python-3.x,google-chrome-devtools,chrome-debugging,Python,Python 3.x,Google Chrome Devtools,Chrome Debugging,使用连接到Docker容器中无头运行的Chrome时,我发现它有时会卡住(下面引用的示例不可靠——您可能需要运行几次): $python3 Python 3.6.8(默认值,2019年1月14日,11:02:34) linux上的[GCC 8.0.1 20180414(实验)[中继修订版259383]] 有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。 >>>进口cproto >>>cp=cproto.cproto()#localhost:9222==我的Chrome容器 >>>

使用连接到Docker容器中无头运行的Chrome时,我发现它有时会卡住(下面引用的示例不可靠——您可能需要运行几次):

$python3
Python 3.6.8(默认值,2019年1月14日,11:02:34)
linux上的[GCC 8.0.1 20180414(实验)[中继修订版259383]]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>进口cproto
>>>cp=cproto.cproto()#localhost:9222==我的Chrome容器
>>>cp.close()
>>>退出()
^CEException在以下情况中被忽略:
回溯(最近一次呼叫最后一次):
文件“/usr/lib/python3.6/threading.py”,第1294行,在
t、 加入
文件“/usr/lib/python3.6/threading.py”,第1056行,在join中
self.\u等待状态锁定()
文件“/usr/lib/python3.6/threading.py”,第1072行,在等待状态锁中
elif lock.acquire(块,超时):
键盘中断
$
这也发生在Chrome正常运行时,在Docker之外有一个UI

不管Chrome可能处理的是什么不好的东西,cproto库会陷入这样的困境似乎有点“糟糕”


有没有办法强制退出cproto?(我是否在上面做了错事,或者这是一个bug?

看起来一些非守护进程线程在主线程退出后仍在运行。此解决方案对我有效(尚未找到根本原因,需要更多调查):

$ 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
$
diff -ur cproto.orig/core/websocket.py cproto/core/websocket.py
--- cproto.orig/core/websocket.py       2021-01-04 01:24:53.000000000 +0000
+++ cproto/core/websocket.py    2021-03-10 04:10:32.228436532 +0000
@@ -38,8 +38,16 @@
     def connect(self, *args, **kwargs):
         super(self.__class__, self).connect(*args, **kwargs)
 
-        threading.Thread(target=self._read_messages).start()
-        threading.Thread(target=self._process_events).start()
+        # threading.Thread(target=self._read_messages).start()
+        # threading.Thread(target=self._process_events).start()
+
+        t1 = threading.Thread(target=self._read_messages)
+        t1.setDaemon(True)
+        t1.start()
+
+        t2 = threading.Thread(target=self._process_events)
+        t2.setDaemon(True)
+        t2.start()
 
     def close(self):
         # Terminates blocking `get` call on events processing thread