这是一个来自 Github 的分叉存储库,当我尝试将其部署到 Heroku 时,它显示错误:
2023-12-31T03:10:27.965787+00:00 app[web.1]:
2023-12-31T03:10:27.965828+00:00 app[web.1]: RuntimeError: can't create new thread at interpreter shutdown
2023-12-31T03:10:27.965992+00:00 app[web.1]: self._executor.open()
2023-12-31T03:10:27.966013+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/site-packages/pymongo/periodic_executor.py", line 87, in open
2023-12-31T03:10:27.966072+00:00 app[web.1]: thread.start()
2023-12-31T03:10:27.966088+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.12/threading.py", line 992, in start
2023-12-31T03:10:27.966229+00:00 app[web.1]: _start_new_thread(self._bootstrap, ())
2023-12-31T03:10:27.966249+00:00 app[web.1]: RuntimeError: can't create new thread at interpreter shutdown
2023-12-31T03:10:28.174616+00:00 heroku[web.1]: Process exited with status 1
2023-12-31T03:10:28.197914+00:00 heroku[web.1]: State changed from starting to crashed
它说:
运行时错误:无法在解释器关闭时创建新线程”
帮我解决这个问题。
我正在尝试使用 Github 存储库创建一个 Telegram 机器人
Python 3.12 引入了一项更改,可防止在主线程退出后创建新线程。目前尚不清楚它是否被视为错误并会被恢复。有关详细信息,请参阅 CPython 问题 #115533。
Thread.join()
方法来完成的,或者将线程生成转换为使用 with ThreadPoolExecutor() as executor: ...
(请参阅文档),它会自动在块末尾等待。