如何在Heroku上停止/杀死python?
在本地,在窗户上,我可以停止线程提出一个例外:
def raise_exception_in_thread(t:Thread):
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(t.ident), ctypes.py_object(SystemExit))
但是,在Heroku上,我的线程不会停止。
我试过 :
ctypes.pythonapi.PyThreadState_SetAsyncExc(t.native_id, ctypes.py_object(SystemExit))
ctypes.pythonapi.PyThreadState_SetAsyncExc(t.ident, ctypes.py_object(SystemExit))
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_ulong(t.native_id), ctypes.py_object(SystemExit))
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_ulong(t.ident), ctypes.py_object(SystemExit))
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(t.native_id), ctypes.py_object(SystemExit))
Locally, on windows, i can stop my thread raising an exception :
def raise_exception_in_thread(t:Thread):
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(t.ident), ctypes.py_object(SystemExit))
But, on Heroku, my thread don't stop.
I tried :
ctypes.pythonapi.PyThreadState_SetAsyncExc(t.native_id, ctypes.py_object(SystemExit))
ctypes.pythonapi.PyThreadState_SetAsyncExc(t.ident, ctypes.py_object(SystemExit))
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_ulong(t.native_id), ctypes.py_object(SystemExit))
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_ulong(t.ident), ctypes.py_object(SystemExit))
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(t.native_id), ctypes.py_object(SystemExit))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方案,如果可以帮助:
我使用async_mode'gevent'在Heroku上部署了一个烧瓶/socketio应用程序:
procfile:
并且能够通过提高例外来停止Heroku上的线程,
我必须使用async_mode'螺纹':
procfile:
https://flask-socketio.readthedocs.io/en/latest/api.html
https://flask-socketio.readthedocs.io.io.ire.readthedocs.io/en/en/latest/deployment。 html
I found a solution if it could help :
I deployed a Flask/SocketIO app on heroku using async_mode 'gevent' :
Procfile:
And to be able to stop a thread on heroku by raising an exception,
i have to deploy the Flask/SocketIO app on heroku using async_mode 'threading' :
Procfile:
https://flask-socketio.readthedocs.io/en/latest/api.html
https://flask-socketio.readthedocs.io/en/latest/deployment.html