一些参考文档:
- c++ - Deadlock when QThread tries to acquire Python GIL via PyGILState_Ensure() - Stack Overflow
- pyeval-initthreads-in-python-3-how-when-to-call-it-the-saga-continues-ad-nau
- Runtime error loading `numpy` · pybind/pybind11 · Discussion #5171 · GitHub
- 这个帖子记录的问题和我的一致,这是因为在c++层面使用python的时候,初始化多次导致的
- 使用子解释器运行Python并行应用
- 最后的结论就是无法移除(这里我换了一个思路,还是使用多进程来处理一些任务吧)
- Python之丢掉万恶的GIL - 掘金
- Awasu » Embedding Python: Using Python in a multi-threaded program,多线程运行python
- Python multi-thread multi-interpreter C API
- 多线程中运行python
- python-sub-interpreters-multiple-threads-example/main.cpp at master · sterin/python-sub-interpreters-multiple-threads-example · GitHub
- 这个文件是一种多线程运行的写法,但是也会有问题,需要提前创建好多个解释器,并不能动态的创建
- 需要提前创建好多个解释器,这个情况并不是很符合我的场景,我希望的是在QT线程对象run的时候动态的创建出来,但是这种情况下我反复调整GIL都不能得到一个正常运行的场景
- 这个过程让我感觉到C api的恶心,未知状态,未知机制,只能一点点的试错
- An example showing how to use sub interpreters and threads in Python · GitHub
- 比较旧的写法,但依旧具有参考意义
- Initialization, Finalization, and Threads
- 官方的文档,还是很有权威的
- Embedding Python in C/C++: Part I - CodeProject
-
[Python Global Interpreter Lock-GIL [Explained in Detail] by VinayShende Medium](https://medium.com/@vinayshende79/python-global-interpreter-lock-gil-explained-in-detail-abcdb206c3e3) - 大概是在很认真的解释什么是GIL,但是就此作罢,多进程处理吧