File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Lib/test/test_free_threading Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ import unittest
2+ from importlib import reload , import_module
3+ from threading import Thread , Barrier
4+
5+ from test .support import threading_helper
6+
7+
8+ class ImportlibThreading (unittest .TestCase ):
9+
10+ @threading_helper .reap_threads
11+ @threading_helper .requires_working_threading ()
12+ def test_reload (self ):
13+ modules = [
14+ "collections.abc" ,
15+ "collections" ,
16+ 'sys' , 'os' ,'sqlite3'
17+ ]
18+
19+ number_of_threads = 2 * len (modules )
20+ number_of_iterations = 600
21+ barrier = Barrier (number_of_threads )
22+ def work (mod ):
23+ barrier .wait ()
24+ for ii in range (number_of_iterations ):
25+ m = import_module (mod )
26+ reload (m )
27+
28+ worker_threads = []
29+ for ii in range (number_of_threads ):
30+ mod = modules [ii % len (modules )]
31+
32+ worker_threads .append (
33+ Thread (target = work , args = [mod ]))
34+ for t in worker_threads :
35+ t .start ()
36+ for t in worker_threads :
37+ t .join ()
38+
39+
40+ if __name__ == "__main__" :
41+ unittest .main ()
You can’t perform that action at this time.
0 commit comments