有什么方法可以在 python3 中完全取消导入共享对象吗?

问题描述 投票:0回答:0

使用

pybind11
,我将我的 C++ 代码绑定到两个共享对象中的 Python3:
A.so
B.so
。他们都使用相同的
libprotobuf.so
.

如果我将它们一起导入,则会发生错误:


[libprotobuf ERROR google/protobuf/descriptor_database.cc:58] File already exists in database: 

[libprotobuf FATAL google/protobuf/descriptor.cc:1370] CHECK failed: GeneratedDatabase()->Add(encoded_file_descr

这是一个已知问题:https://groups.google.com/g/protobuf/c/RZRCnOywdSk/m/s5QvifLCBgAJ?utm_medium=email&utm_source=footer

因为我可以单独使用这两个

.so
,所以我决定先使用
A.so
,然后取消导入:


sys.modules.pop(module_name)

del module_name

print(sys.modules)

在输出中,我的模块中没有

A.so

但是,当我导入

B.so
时,出现错误:


[libprotobuf ERROR google/protobuf/descriptor_database.cc:111] Symbol name "a.b.c" conflicts with the existing symbol "a.b.c".

[libprotobuf FATAL google/protobuf/descriptor.cc:1394] CHECK failed: generated_database_->Add(encoded_file_descriptor, size): 

Aborted (core dumped)

有什么方法可以在 python3 中完全取消导入共享对象吗?

我试过:


sys.modules.pop(module_name)

del module_name

print(sys.modules)
python-3.x shared-libraries pybind11
© www.soinside.com 2019 - 2024. All rights reserved.