Deadlocks?使用一个导入来检测线程在python中的挂起位置。
hanging_threads的Python项目详细描述
死锁?检测线程在python中的挂起位置。
安装
您可以使用pip安装模块:
pip install hanging_threads
如果您在windows下,则可以打开命令行程序“cmd”并键入
py -m pip install hanging_threads
用法
开始监视就像调用start_monitoring()函数一样简单。
fromhanging_threadsimportstart_monitoringmonitoring_thread=start_monitoring()
您还可以传递其他参数。
monitoring_thread=start_monitoring(seconds_frozen=10,test_interval=100)
示例中的值是默认值。这意味着支票将在10 每秒次。如果线程被冻结至少10秒,那么堆栈 被转储到标准错误流中。这种情况每10秒发生一次 而在检查期间注册的堆栈中没有任何更改。支票是在 间隔100毫秒。
注意,将线程对象保存到变量中是有意义的,这样您或 如果需要的话,其他人可以阻止这种烦人的垃圾。 例如,您可能希望在python shell中执行此操作。
monitoring_thread.stop()