@@ -549,7 +549,9 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
549549 int need_to_reenable_gc = 0 ;
550550 char * const * exec_array , * const * argv = NULL , * const * envp = NULL ;
551551 Py_ssize_t arg_num ;
552+ #ifdef WITH_THREAD
552553 int import_lock_held = 0 ;
554+ #endif
553555
554556 if (!PyArg_ParseTuple (
555557 args , "OOpOOOiiiiiiiiiiO:fork_exec" ,
@@ -644,8 +646,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
644646 preexec_fn_args_tuple = PyTuple_New (0 );
645647 if (!preexec_fn_args_tuple )
646648 goto cleanup ;
649+ #ifdef WITH_THREAD
647650 _PyImport_AcquireLock ();
648651 import_lock_held = 1 ;
652+ #endif
649653 }
650654
651655 if (cwd_obj != Py_None ) {
@@ -688,12 +692,14 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
688692 /* Capture the errno exception before errno can be clobbered. */
689693 PyErr_SetFromErrno (PyExc_OSError );
690694 }
691- if (preexec_fn != Py_None &&
692- _PyImport_ReleaseLock () < 0 && !PyErr_Occurred ()) {
695+ #ifdef WITH_THREAD
696+ if (preexec_fn != Py_None
697+ && _PyImport_ReleaseLock () < 0 && !PyErr_Occurred ()) {
693698 PyErr_SetString (PyExc_RuntimeError ,
694699 "not holding the import lock" );
695700 }
696701 import_lock_held = 0 ;
702+ #endif
697703
698704 /* Parent process */
699705 if (envp )
@@ -716,8 +722,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
716722 return PyLong_FromPid (pid );
717723
718724cleanup :
725+ #ifdef WITH_THREAD
719726 if (import_lock_held )
720727 _PyImport_ReleaseLock ();
728+ #endif
721729 if (envp )
722730 _Py_FreeCharPArray (envp );
723731 if (argv )
0 commit comments