在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/