File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -2253,11 +2253,31 @@ def test_names(self):
22532253 self .assertEqual (obj .__name__ , name )
22542254 self .assertEqual (obj .__qualname__ , name )
22552255
2256- def test_module_dealloc (self ):
2256+ def test_module_weakref (self ):
22572257 mod = types .ModuleType ("temp_mod" )
2258+ common_ref = weakref .ref (mod )
2259+ threads = []
2260+ n_threads = 10
2261+ b = threading .Barrier (n_threads )
2262+
2263+ def weakref_mod_worker ():
2264+ b .wait ()
2265+ r = weakref .ref (mod )
2266+ rr = r ()
2267+ self .assertIs (rr , mod )
2268+ self .assertIs (rr , common_ref ())
2269+
2270+ for i in range (n_threads ):
2271+ t = threading .Thread (target = weakref_mod_worker )
2272+ threads .append (t )
2273+ t .start ()
2274+
2275+ for t in threads :
2276+ t .join ()
2277+
22582278 r = weakref .ref (mod )
22592279 self .assertIsNotNone (r , "weak ref to a module should not be None" )
2260-
2280+ self . assertIs ( r (), common_ref ())
22612281 del mod
22622282
22632283
You can’t perform that action at this time.
0 commit comments