File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -7367,6 +7367,40 @@ def gen():
73677367 res = self .assert_python_in_subinterp (True , script , setup = '' )
73687368 self .assertFalse (res .err )
73697369
7370+ script = textwrap .dedent ("""
7371+ import gc
7372+ import sys
7373+ import _testcapi
7374+
7375+ def emulate_interp_restart():
7376+ del sys.modules['_datetime']
7377+ try:
7378+ del sys.modules['datetime']
7379+ except KeyError:
7380+ pass
7381+ gc.collect() # unload
7382+
7383+ _testcapi.test_datetime_capi() # only once
7384+ timedelta = _testcapi.get_capi_types()['timedelta']
7385+ emulate_interp_restart()
7386+ timedelta(days=1)
7387+ emulate_interp_restart()
7388+
7389+ def gen():
7390+ try:
7391+ yield
7392+ finally:
7393+ # Exceptions are ignored here
7394+ assert not sys.modules
7395+ timedelta(days=1)
7396+
7397+ it = gen()
7398+ next(it)
7399+ """ )
7400+ with self .subTest ('MainInterpreter Restart' ):
7401+ res = script_helper .assert_python_ok ('-c' , script )
7402+ self .assertIn (b'ImportError: sys.meta_path is None' , res .err )
7403+
73707404 script = textwrap .dedent ("""
73717405 import sys
73727406 timedelta = _testcapi.get_capi_types()['timedelta']
You can’t perform that action at this time.
0 commit comments