Repository navigation
initialize_globals()在边缘场景下的获取堆栈卡住问题 #34
Copy link
Copy link
Open
Description
Activity
能提供下测试的python脚本吗
能提供下测试的python脚本吗
add.cpp
#include <pybind11/pybind11.h> #include <thread> // 包含线程相关的头文件 #include <chrono> // #include <stdio.h> int add(int a, int b) { while(1) { std::this_thread::sleep_for(std::chrono::seconds(2)); // 每2秒暂停一次 } //printf("aaaaaa\n"); //std::this_thread::sleep_for(std::chrono::seconds(2)); // 每秒暂停一次 // 可以在这里加入一些逻辑,比如打印日志等 // std::cout << "Stuck in an infinite loop..." << std::endl; return a + b; } int my_add(int a, int b){ return add(a, b); } int my_add_function(int a, int b){ return my_add(a, b); } PYBIND11_MODULE(add, m) { m.def("add_aa", &my_add_function, "A function that adds two numbers"); }
main.py
import add import time import threading # result = add.add_aa(3, 5) # print(f"The result is: {result}") def add_numbers_2(): add_numbers_1() def add_numbers_1(): add_numbers() def add_numbers(): while True: time.sleep(10) result = add.add_aa(3, 5) #print(f"The result is: {result}") if __name__ == "__main__": add_numbers_2()
setup.py
from setuptools import setup, Extension from pybind11.setup_helpers import Pybind11Extension, build_ext ext_modules = [ Pybind11Extension( "add", ["add.cpp"], extra_compile_args=['-g', '-O0'], # 添加-O0禁用优化,增强调试效果 define_macros=[('DEBUG', '1')], # 可选:定义DEBUG宏 ), ] setup( name="add", ext_modules=ext_modules, cmdclass={"build_ext": build_ext}, )
运行命令
PROBING=1 PROBING_PORT=9922 python main.py
- added a commit that references this issue
on Jun 19, 2026
Metadata
Metadata
Assignees
Labels
No labels







问题
python进程调用so库抢占GIL锁时, 获取堆栈发送命令后会卡住