diff options
author | neonene <53406459+neonene@users.noreply.github.com> | 2024-06-12 16:46:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-12 16:46:39 (GMT) |
commit | 127c1d2771749853e287632c086b6054212bf12a (patch) | |
tree | f036cf29942269141fdc218340e1d6cbbf849c14 /Lib | |
parent | fabcf6bc8f89f008319442dea614d5cbeb959544 (diff) | |
download | cpython-127c1d2771749853e287632c086b6054212bf12a.zip cpython-127c1d2771749853e287632c086b6054212bf12a.tar.gz cpython-127c1d2771749853e287632c086b6054212bf12a.tar.bz2 |
gh-71587: Drop local reference cache to `_strptime` module in `_datetime` (gh-120224)
The _strptime module object was cached in a static local variable (in the datetime.strptime() implementation). That's a problem when it crosses isolation boundaries, such as reinitializing the runtme or between interpreters. This change fixes the problem by dropping the static variable, instead always relying on the normal sys.modules cache (via PyImport_Import()).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_embed.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index d94c63a..634513e 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -404,6 +404,15 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase): out, err = self.run_embedded_interpreter("test_repeated_init_exec", code) self.assertEqual(out, '9\n' * INIT_LOOPS) + def test_datetime_reset_strptime(self): + code = ( + "import datetime;" + "d = datetime.datetime.strptime('2000-01-01', '%Y-%m-%d');" + "print(d.strftime('%Y%m%d'))" + ) + out, err = self.run_embedded_interpreter("test_repeated_init_exec", code) + self.assertEqual(out, '20000101\n' * INIT_LOOPS) + @unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi") class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): |