Skip to content

Commit 3dc2bee

Browse files
committed
add test for concurrent reload
1 parent 905549a commit 3dc2bee

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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()

0 commit comments

Comments
 (0)