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):
2253
2253
self .assertEqual (obj .__name__ , name )
2254
2254
self .assertEqual (obj .__qualname__ , name )
2255
2255
2256
- def test_module_dealloc (self ):
2256
+ def test_module_weakref (self ):
2257
2257
mod = types .ModuleType ("temp_mod" )
2258
+ common_ref = weakref .ref (mod )
2259
+ threads = []
2260
+ n_threads = 5
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
+
2258
2278
r = weakref .ref (mod )
2259
2279
self .assertIsNotNone (r , "weak ref to a module should not be None" )
2260
-
2280
+ self . assertIs ( r (), common_ref ())
2261
2281
del mod
2262
2282
2263
2283
You can’t perform that action at this time.
0 commit comments