【发布时间】:2019-03-09 03:41:21
【问题描述】:
我创建了一个执行多个线程的脚本,其中每个线程向 API 发出请求以检索一些数据。不幸的是,其中一个线程可能会遇到断开连接错误(可能是由于站点的 API 过载),因此,整个 python 脚本会无限期挂起......当其中一名工作人员时,如何强制脚本正常退出线程有断开连接错误?我以为使用terminate 会关闭线程。
我的代码:
runId = sys.argv[1]
trth = TrThDownload(runId)
data = trth.data
concurrences = min(len(data),10)
p = pool.ThreadPool(concurrences)
p.map(trth.runDownloader, data)
p.terminate()
p.close()
p.join()
【问题讨论】:
-
嗯,这很有趣。以异常终止的线程不应挂起应用程序。也许某些线程卡在 I/O 操作中?调整超时可能会有所帮助。
-
我无法重现该问题。请edit您的问题并提供minimal reproducible example。
标签: python multithreading exit terminate