diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 7649e213d7..11e996a0d9 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -1125,6 +1125,7 @@ endif() # limit to only test on windows first, due to a runtime path issue on linux if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD + AND NOT onnxruntime_ENABLE_TRAINING AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin|iOS" AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Android") AND NOT onnxruntime_BUILD_WEBASSEMBLY diff --git a/onnxruntime/core/framework/provider_bridge_ort.cc b/onnxruntime/core/framework/provider_bridge_ort.cc index 84067dea51..c22ac30b6b 100644 --- a/onnxruntime/core/framework/provider_bridge_ort.cc +++ b/onnxruntime/core/framework/provider_bridge_ort.cc @@ -886,8 +886,9 @@ struct ProviderSharedLibrary { } ProviderSharedLibrary() = default; - ~ProviderSharedLibrary() { /*assert(!handle_);*/ - } // We should already be unloaded at this point (disabled until Python shuts down deterministically) + ~ProviderSharedLibrary() { + // assert(!handle_); // We should already be unloaded at this point (disabled until Python shuts down deterministically) + } private: void* handle_{}; @@ -904,7 +905,7 @@ bool InitProvidersSharedLibrary() { struct ProviderLibrary { ProviderLibrary(const char* filename, bool unload = true) : filename_{filename}, unload_{unload} {} ~ProviderLibrary() { - assert(!handle_); // We should already be unloaded at this point + // assert(!handle_); // We should already be unloaded at this point (disabled until Python shuts down deterministically) } Provider* Get() { diff --git a/onnxruntime/python/onnxruntime_pybind_state.cc b/onnxruntime/python/onnxruntime_pybind_state.cc index 04fe589447..99482941e4 100644 --- a/onnxruntime/python/onnxruntime_pybind_state.cc +++ b/onnxruntime/python/onnxruntime_pybind_state.cc @@ -2104,6 +2104,13 @@ PYBIND11_MODULE(onnxruntime_pybind11_state, m) { const logging::Logger& default_logger = logging::LoggingManager::DefaultLogger(); LOGS(default_logger, WARNING) << "Init provider bridge failed."; } + +// It appears that only windows can safely unload the providers from python at this point +#ifdef _WIN32 + atexit([] { + UnloadSharedProviders(); + }); +#endif #endif #ifdef ENABLE_TRAINING