File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,26 @@ def func():
309309 self .assertRegex (stdout , rb"""\A\s*func=None""" )
310310 self .assertFalse (stderr )
311311
312+ def test_datetime_weakref_cycle (self ):
313+ # https://github.com/python/cpython/issues/132413
314+ # If the weakref used by the datetime extension gets cleared by the GC (due to being
315+ # in an unreachable cycle) then datetime functions would crash (get_module_state()
316+ # was returning a NULL pointer). This bug is fixed by clearing weakrefs without
317+ # callbacks *after* running finalizers.
318+ code = """if 1:
319+ import _datetime
320+ class C:
321+ def __del__(self):
322+ print('__del__ called')
323+ _datetime.timedelta(days=1) # crash?
324+
325+ l = [C()]
326+ l.append(l)
327+ """
328+ rc , stdout , stderr = assert_python_ok ("-c" , code )
329+ self .assertEqual (rc , 0 )
330+ self .assertEqual (stdout .strip (), b'__del__ called' )
331+
312332 @refcount_test
313333 def test_frame (self ):
314334 def f ():
You can’t perform that action at this time.
0 commit comments