gpt4 book ai didi

python - 如何终止在后端执行长时间运行的 C/C++ 代码的 python 解释器?

转载 作者:行者123 更新时间:2023-11-30 16:48:00 25 4
gpt4 key购买 nike

在Python中documentation ,似乎从 python 端发送的信号无法杀死长时间运行的 C/C++ 进程:

A long-running calculation implemented purely in C (such as regular expression matching on a large body of text) may run uninterrupted for an arbitrary amount of time, regardless of any signals received. The Python signal handlers will be called when the calculation finishes.

有解决办法吗?我可以在 C/C++ 端实现一些东西(即回调函数?)来捕获键盘中断吗?

非常感谢您的帮助!

最佳答案

找到解决方法 here ,似乎将长时间运行的 CPython 程序设置为守护线程是处理它的一种方法。

关于python - 如何终止在后端执行长时间运行的 C/C++ 代码的 python 解释器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43151389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com