From af32e3fe1aa48ebc831ec099e394ce9f38f8daf5 Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Mon, 8 Aug 2022 13:34:20 -0700 Subject: [PATCH] run ClearRegisteredBenchmarks at exit (#1463) --- bindings/python/google_benchmark/__init__.py | 2 ++ bindings/python/google_benchmark/benchmark.cc | 1 + 2 files changed, 3 insertions(+) diff --git a/bindings/python/google_benchmark/__init__.py b/bindings/python/google_benchmark/__init__.py index b249ca85..3dfabfb3 100644 --- a/bindings/python/google_benchmark/__init__.py +++ b/bindings/python/google_benchmark/__init__.py @@ -26,6 +26,7 @@ Example usage: if __name__ == '__main__': benchmark.main() """ +import atexit from absl import app from google_benchmark import _benchmark @@ -158,3 +159,4 @@ def main(argv=None): # Methods for use with custom main function. initialize = _benchmark.Initialize run_benchmarks = _benchmark.RunSpecifiedBenchmarks +atexit.register(_benchmark.ClearRegisteredBenchmarks) diff --git a/bindings/python/google_benchmark/benchmark.cc b/bindings/python/google_benchmark/benchmark.cc index ea40990e..5614b928 100644 --- a/bindings/python/google_benchmark/benchmark.cc +++ b/bindings/python/google_benchmark/benchmark.cc @@ -179,5 +179,6 @@ PYBIND11_MODULE(_benchmark, m) { py::return_value_policy::reference); m.def("RunSpecifiedBenchmarks", []() { benchmark::RunSpecifiedBenchmarks(); }); + m.def("ClearRegisteredBenchmarks", benchmark::ClearRegisteredBenchmarks); }; } // namespace