Fix python shutdown

This commit is contained in:
Ryan Hill 2021-04-28 23:53:28 -07:00
parent 3717440937
commit 5a3a8fe2d0
3 changed files with 12 additions and 18 deletions

View file

@ -902,8 +902,9 @@ bool InitProvidersSharedLibrary() {
struct ProviderLibrary {
ProviderLibrary(const char* filename) : filename_{filename} {}
~ProviderLibrary() { /*assert(!handle_);*/
} // We should already be unloaded at this point (disabled until Python shuts down deterministically)
~ProviderLibrary() {
assert(!handle_); // We should already be unloaded at this point
}
Provider* Get() {
if (provider_)

View file

@ -6,5 +6,6 @@
namespace onnxruntime {
bool InitProvidersSharedLibrary();
void UnloadSharedProviders();
} // namespace onnxruntime

View file

@ -782,7 +782,7 @@ static void RegisterExecutionProviders(InferenceSession* sess, const std::vector
auto shared_lib_path_it = it->second.find(kExecutionProviderSharedLibraryPath);
if (shared_lib_path_it != it->second.end()) {
// this is an EP with dynamic loading
// construct the provider option
// construct the provider option
ProviderOptions provider_options;
for (auto option : it->second) {
if (option.first != kExecutionProviderSharedLibraryPath)
@ -790,7 +790,7 @@ static void RegisterExecutionProviders(InferenceSession* sess, const std::vector
}
auto p_ep = LoadExecutionProvider(shared_lib_path_it->second, provider_options);
ORT_THROW_IF_ERROR(sess->RegisterExecutionProvider(
std::move(p_ep)));
std::move(p_ep)));
continue;
}
}
@ -2092,12 +2092,16 @@ PYBIND11_MODULE(onnxruntime_pybind11_state, m) {
#if !defined(ORT_MINIMAL_BUILD) || defined(ORT_EXTENDED_MINIMAL_BUILD) || defined(ORT_MINIMAL_BUILD_CUSTOM_OPS)
Ort::SessionOptions tmp_options;
if(!InitProvidersSharedLibrary()){
if (!InitProvidersSharedLibrary()) {
const logging::Logger& default_logger = logging::LoggingManager::DefaultLogger();
LOGS(default_logger, WARNING) << "Init provider bridge failed.";
}
atexit([] {
UnloadSharedProviders();
});
#endif
#ifdef ENABLE_TRAINING
addObjectMethodsForTraining(m);
#endif // ENABLE_TRAINING
@ -2108,21 +2112,9 @@ PYBIND11_MODULE(onnxruntime_pybind11_state, m) {
#endif
}
struct OutputOnDestroy {
~OutputOnDestroy() {
std::cerr << "OutputOnDestroy: " << p_message << std::endl;
}
const char* p_message;
};
static OutputOnDestroy v1{"After Environment Destroyed"};
// static variable used to create inference session and training session.
static std::unique_ptr<Environment> session_env;
static OutputOnDestroy v2{"Before Environment Destroyed"};
void InitializeEnv() {
auto initialize = [&]() {
// Initialization of the module