diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 205b15bb18..1df773138a 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -4416,23 +4416,25 @@ datetime_utcfromtimestamp(PyObject *cls, PyObject *args) return result; } +static PyObject *strptime_module = NULL; + /* Return new datetime from _strptime.strptime_datetime(). */ static PyObject * datetime_strptime(PyObject *cls, PyObject *args) { - static PyObject *module = NULL; PyObject *string, *format; _Py_IDENTIFIER(_strptime_datetime); if (!PyArg_ParseTuple(args, "UU:strptime", &string, &format)) return NULL; - if (module == NULL) { - module = PyImport_ImportModuleNoBlock("_strptime"); - if (module == NULL) + if (strptime_module == NULL) { + strptime_module = PyImport_ImportModuleNoBlock("_strptime"); + if (strptime_module == NULL) return NULL; } - return _PyObject_CallMethodIdObjArgs(module, &PyId__strptime_datetime, + return _PyObject_CallMethodIdObjArgs(strptime_module, + &PyId__strptime_datetime, cls, string, format, NULL); } @@ -5627,7 +5629,9 @@ static PyDateTime_CAPI CAPI = { new_time_ex2 }; - +static void module_free(void) { + strptime_module = NULL; +} static struct PyModuleDef datetimemodule = { PyModuleDef_HEAD_INIT, @@ -5638,7 +5642,7 @@ static struct PyModuleDef datetimemodule = { NULL, NULL, NULL, - NULL + module_free }; PyMODINIT_FUNC