如何在Heroku上停止/杀死python?

发布于 2025-02-01 00:47:31 字数 733 浏览 5 评论 0原文

在本地,在窗户上,我可以停止线程提出一个例外:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2025-02-08 00:47:31

我找到了一个解决方案,如果可以帮助:

我使用async_mode'gevent'在Heroku上部署了一个烧瓶/socketio应用程序:

app = Flask(__name__)
socketio = SocketIO(app, async_mode='gevent')

procfile:

web: gunicorn -k gevent -w 1 main:app

并且能够通过提高例外来停止Heroku上的线程,

我必须使用async_mode'螺纹':

app = Flask(__name__)
socketio = SocketIO(app, async_mode='threading')

procfile:

web: gunicorn -w 1 --threads 100 main:app

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' :

app = Flask(__name__)
socketio = SocketIO(app, async_mode='gevent')

Procfile:

web: gunicorn -k gevent -w 1 main:app

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' :

app = Flask(__name__)
socketio = SocketIO(app, async_mode='threading')

Procfile:

web: gunicorn -w 1 --threads 100 main:app

https://flask-socketio.readthedocs.io/en/latest/api.html
https://flask-socketio.readthedocs.io/en/latest/deployment.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文