Pybind11 and problem with script after 'reload'

Hello. I’m not professional Python programmer and I have no any experience in it. But my current task/problem is very close to Python. My task is to bind python code of some ml project with our c++ application (with one of our dynamically loaded library). I use pybind11 sources and python3.6m library for that. And it works. But the second part of my task is to make our library reloadable, and here is the problem.

i’m sorry if my english is not good.

In C++ code i have pybind11::object scope_ object. In init function of our library I run pybind11::initilaize_interpreter() and pybind11::eval_file(here is ml script, scope_). Because we use numpy in our python script i also call NDArrayConverter::init_numpy(). After that i run pybind11::exec(‘command to create object’, scope_) and pybind11::object dict = scope_[created object].attr(“process_frame”)(params…) to take results.
When i started to write “attribute((destructor)) void fini()” function to unload our library i thought that pybind11::finalize_interpreter() must be there. But because we use numpy next initialization seg faults on init_numpy(). I found explanation here - https://github.com/numpy/numpy/issues/8097.
So i removed finalize_interpreter() from stop function and added if() to make initialize_interpreter() only once at start of our application. Also i remove all variables from pybind11::object dictionary so at start this object:
{‘name’: ‘main’, ‘doc’: None, ‘package’: None, ‘loader’: <class ‘_frozen_importlib.BuiltinImporter’>, ‘spec’: None, ‘annotations’: {}, ‘builtins’: <module ‘builtins’ (built-in)>, ‘file’: ‘/usr/local/…/update.py’, ‘sys’: <module ‘sys’ (built-in)>, ‘os’: <module ‘os’ from ‘/usr/lib64/python3.6/os.py’>, ‘absolute_path’: ‘/usr/local/…/pycode’, ‘cv2’: <module ‘cv2.cv2’ from ‘/usr/local/lib64/python3.6/site-packages/cv2/cv2.cpython-36m-x86_64-linux-gnu.so’>, ‘GaussianMixture’: <class ‘sklearn.mixture.gaussian_mixture.GaussianMixture’>, ‘np’: <module ‘numpy’ from ‘/usr/local/lib64/python3.6/site-packages/numpy/init.py’>, ‘stabilizer’: <module ‘stabilizer’ from ‘/usr/local/…/stabilizer.py’>, ‘stabilizer_helper’: <module ‘stabilizer_helper’ from ‘/usr/local/…/stabilizer_helper.py’>, ‘json’: <module ‘json’ from ‘/usr/lib64/python3.6/json/init.py’>, ‘atexit’: <module ‘atexit’ (built-in)>, ‘predict_label_gmm_model’: <function predict_label_gmm_model at 0x7fff7bff3f28>, ‘crop_image’: <function crop_image at 0x7ffe813f3e18>, ‘all_done’: <function all_done at 0x7ffe813f3ea0>, ‘crop_circle_from_image’: <function crop_circle_from_image at 0x7ffe813f3f28>, ‘TrafficLightUpdate’: <class ‘main.TrafficLightUpdate’>, ‘process_video’: <function process_video at 0x7ffe80ceb048>, ‘draw_rois_on_video’: <function draw_rois_on_video at 0x7ffe80ceb268>, ‘info’: {‘1_1’: {‘1’: [1488, 814, 7], ‘2’: [1486, 839, 7], ‘3’: [1486, 865, 7], ‘5’: [1510, 867, 7]}}, ‘traffic_light’: <main.TrafficLightUpdate object at 0x7ffeb4557f60>}

and after stop but before destructor

{‘name’: ‘main’, ‘doc’: None, ‘package’: None, ‘loader’: <class ‘_frozen_importlib.BuiltinImporter’>, ‘spec’: None, ‘annotations’: {}, ‘builtins’: <module ‘builtins’ (built-in)>}

i make it by calling pybind11::exec(“del ****”, scope_);

After reload i can create object of type from python script with ‘pybind11::exec(‘command to create object’, scope_)’ so init method works. But after that i call pybind11::object dict = scope_[created object].attr(“process_frame”)(params…) to take results and this method doesn’t start at all and makes my thread hang on.

Could anyone give me some advices please?