diff --git a/m4/guestfs-python.m4 b/m4/guestfs-python.m4 index 2e736875c..0a49b7fc8 100644 --- a/m4/guestfs-python.m4 +++ b/m4/guestfs-python.m4 @@ -88,6 +88,18 @@ AS_IF([test "x$enable_python" != "xno"],[ AC_MSG_RESULT([$PYTHON_EXT_SUFFIX]) AC_CHECK_PROGS([PYCODESTYLE],[pycodestyle],[no]) + + dnl Look for some optional symbols in libpython. + old_LIBS="$LIBS" + + PYTHON_BLDLIBRARY=`$PYTHON -c "import distutils.sysconfig; \ + print (distutils.sysconfig.get_config_var('BLDLIBRARY'))"` + AC_CHECK_LIB([c],[_Py_IsFinalizing], + [AC_DEFINE([HAVE_PY_ISFINALIZING],1, + [Found _Py_IsFinalizing in libpython.])], + [],[$PYTHON_BLDLIBRARY]) + + LIBS="$old_LIBS" fi AC_SUBST(PYTHON_PREFIX) diff --git a/python/handle.c b/python/handle.c index 21077bba9..2db021f1b 100644 --- a/python/handle.c +++ b/python/handle.c @@ -121,8 +121,10 @@ guestfs_int_py_event_callback_wrapper (guestfs_h *g, PyObject *py_r; int threads_initialized = PyEval_ThreadsInitialized (); +#ifdef HAVE_PY_ISFINALIZING if (_Py_IsFinalizing ()) return; +#endif if (threads_initialized) py_save = PyGILState_Ensure ();