Index: subversion/bindings/swig/core.i =================================================================== --- subversion/bindings/swig/core.i (revision 16458) +++ subversion/bindings/swig/core.i (working copy) @@ -635,11 +635,6 @@ PyObject *svn_swig_py_register_cleanup(PyObject *py_pool, apr_pool_t *pool); %init %{ -/* Theoretically, we should be checking for errors from these calls, - but I do not know of any useful way to signal an error to Python - from within a module initialization function. */ -apr_initialize(); -atexit(apr_terminate); /* This is a hack. I dunno if we can count on SWIG calling the module "m" */ PyModule_AddObject(m, "SubversionException", Index: subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c =================================================================== --- subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (revision 16458) +++ subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (working copy) @@ -66,12 +66,24 @@ static apr_threadkey_t *_saved_thread_key = NULL; static apr_pool_t *_saved_thread_pool = NULL; #endif +static int apr_initialized = 0; void svn_swig_py_release_py_lock(void) { #ifdef ACQUIRE_PYTHON_LOCK PyThreadState *thread_state; +#endif + if (!apr_initialized) { + /* Theoretically, we should be checking for errors from these calls, + but I do not know of any useful way to signal an error to Python + from here. */ + apr_initialize(); + atexit(apr_terminate); + apr_initialized = 1; + } + +#ifdef ACQUIRE_PYTHON_LOCK if (_saved_thread_key == NULL) { /* Obviously, creating a top-level pool for this is pretty stupid. */ apr_pool_create(&_saved_thread_pool, NULL);