diff -r 6b07f261ccf4 Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c Thu Sep 15 16:52:54 2016 -0400 +++ b/Modules/_datetimemodule.c Thu Sep 15 18:04:49 2016 -0400 @@ -4418,24 +4418,26 @@ 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_CallMethodId(module, &PyId__strptime_datetime, "OOO", - cls, string, format); + return _PyObject_CallMethodId(strptime_module, + &PyId__strptime_datetime, "OOO", + cls, string, format); } /* Return new datetime from date/datetime and time arguments. */ @@ -5632,18 +5634,23 @@ new_time_ex2 }; - +static int +module_clear(PyObject *self) +{ + Py_CLEAR(strptime_module); + return 0; +} static struct PyModuleDef datetimemodule = { PyModuleDef_HEAD_INIT, "_datetime", "Fast implementation of the datetime type.", -1, - module_methods, - NULL, - NULL, - NULL, - NULL + module_methods, /* m_methods */ + NULL, /* m_slots */ + NULL, /* m_traverse */ + module_clear, /* m_clear */ + NULL /* m_free */ }; PyMODINIT_FUNC