Skip to content

Commit 9df1177

Browse files
committed
Fix race condition on linux
Iterating through `sys.modules` may raise an exception due to size changes when reloading packages. Hence convert to a tuple, first. Simplify code a bit.
1 parent ea7762d commit 9df1177

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

unittesting/reloader.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def module_in_package(module):
3535
or any(map(in_package_path, paths))
3636
)
3737

38-
return {
39-
name: module
40-
for name, module in sys.modules.items()
38+
return (
39+
name
40+
for name, module in tuple(sys.modules.items())
4141
if module_in_package(module)
42-
}
42+
)
4343

4444

4545
def package_plugins(pkg_name):
@@ -83,11 +83,7 @@ def async_reload_package(pkg_name):
8383

8484

8585
def _reload_package(pkg_name):
86-
all_modules = {
87-
module_name: module
88-
for module_name, module in get_package_modules(pkg_name).items()
89-
}
90-
plugins = [plugin for plugin in package_plugins(pkg_name)]
86+
plugins = package_plugins(pkg_name)
9187

9288
# Tell Sublime to unload plugins
9389
for plugin in plugins:
@@ -96,7 +92,7 @@ def _reload_package(pkg_name):
9692
sublime_plugin.unload_module(module)
9793

9894
# Unload modules
99-
for module_name in all_modules:
95+
for module_name in get_package_modules(pkg_name):
10096
sys.modules.pop(module_name)
10197

10298
sys.modules[pkg_name] = importlib.import_module(pkg_name)

0 commit comments

Comments
 (0)