Skip to content

Commit c73710d

Browse files
authored
Register cleanup function reliably (#2730)
#### Reference Issues/PRs <!--Example: Fixes #1234. See also #3456.--> https://man312219.monday.com/boards/7852509418/pulses/18261646279 #### What does this implement or fix? There is possibility which arcticdb python objects has been released only after the library import is cleaned up. In that case, if any object logs while deconstructing, the null log instance will make the process seg fault. Register the cleanup function properly so it will cleanup when the interpreter de-initialized instead of when the module is unloaded #### Any other comments? No test can be given as I can't repeat the issue in a standalone script. Still pybind11 has warned this may happen: https://pybind11.readthedocs.io/en/stable/advanced/misc.html#module-destructors #### Checklist <details> <summary> Checklist for code changes... </summary> - [ ] Have you updated the relevant docstrings, documentation and copyright notice? - [ ] Is this contribution tested against [all ArcticDB's features](../docs/mkdocs/docs/technical/contributing.md)? - [ ] Do all exceptions introduced raise appropriate [error messages](https://docs.arcticdb.io/error_messages/)? - [ ] Are API changes highlighted in the PR description? - [ ] Is the PR labelled as enhancement or bug so it appears in autogenerated release notes? </details> <!-- Thanks for contributing a Pull Request to ArcticDB! Please ensure you have taken a look at: - ArcticDB's Code of Conduct: https://github.com/man-group/ArcticDB/blob/master/CODE_OF_CONDUCT.md - ArcticDB's Contribution Licensing: https://github.com/man-group/ArcticDB/blob/master/docs/mkdocs/docs/technical/contributing.md#contribution-licensing -->
1 parent 7c96710 commit c73710d

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

cpp/arcticdb/python/python_module.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,8 @@ PYBIND11_MODULE(arcticdb_ext, m) {
382382
register_metrics(m.def_submodule("metrics"));
383383
register_type_handlers();
384384

385-
auto cleanup_callback = []() {
386-
using namespace arcticdb;
387-
ARCTICDB_DEBUG(log::version(), "Running cleanup callback");
388-
shutdown_globals();
389-
};
390-
391-
m.add_object("_cleanup", py::capsule(cleanup_callback));
392-
393385
register_termination_handler();
386+
Py_AtExit(shutdown_globals);
394387

395388
#ifdef VERSION_INFO
396389
m.attr("__version__") = VERSION_INFO;

cpp/arcticdb/util/global_lifetimes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ std::shared_ptr<ModuleData> ModuleData::instance_;
6363
std::once_flag ModuleData::init_flag_;
6464

6565
void shutdown_globals() {
66+
ARCTICDB_DEBUG(log::version(), "Running shutdown_globals");
6667
async::TaskScheduler::stop_active_threads();
6768
storage::mongo::MongoInstance::destroy_instance();
6869
ModuleData::destroy_instance();

0 commit comments

Comments
 (0)