From 6d2f9db498d95a2958b325d006e143c2b5dc0aad Mon Sep 17 00:00:00 2001 From: Pascal Brogle Date: Thu, 16 Feb 2023 12:29:16 +0100 Subject: [PATCH] [sg fromlist] fix: don't call nng_fini() by default PR https://github.com/codypiersall/pynng/pull/125 --- pynng/nng.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pynng/nng.py b/pynng/nng.py index b25682c..910b42c 100644 --- a/pynng/nng.py +++ b/pynng/nng.py @@ -34,9 +34,15 @@ # during a callback to _nng_pipe_cb # * Cleanup background queue threads used by NNG +# NOTE: enabling this can lead to nng panic / crash on python runtime shutdown. Depending on when the atexit function +# is called and objects garbage are collected, it might be possible that nng_fini is already called, but we are is +# still calling the nng lib (e.g. nni_aio_free by AIOHelper.__del__). + +nng_fini_at_exit = False def _pynng_atexit(): - lib.nng_fini() + if nng_fini_at_exit: + lib.nng_fini() atexit.register(_pynng_atexit)