Код: Выделить всё
Py_InitializeEx(0); // Skip installing signal handlers
auto gil = PyGILState_Ensure();
// ... running Python code
PyGILState_Release(gil);
Код: Выделить всё
#define pyscope() \
PyGILState_STATE gstate = PyGILState_Ensure(); \
utils::scope_guard sggstate([&]() \
{ \
PyGILState_Release(gstate); \
});
< /code>
Когда я хочу освободить Python, я звоню (из C-thread, не обязательно тот, кто инициализировал Python): < /p>
PyGILState_STATE gstate = PyGILState_Ensure();
int res = Py_FinalizeEx(); //
Отладка и чтение кода раскрыло, что он висит во время присоединения потоков. Я могу воспроизвести тупик, запустив следующий код с помощью Pyrun_simplestring Код: Выделить всё
import threading
for t in threading.enumerate():
print('get_ident: {} ; native: {}'.format(t.ident, t.native_id))
if not threading.current_thread().ident == t.ident:
t.join()
Подробнее здесь: https://stackoverflow.com/questions/758 ... g-shutdown
Мобильная версия