Skip to content

Commit

Permalink
packages: avoid race in use of sys.modules
Browse files Browse the repository at this point in the history
By iterating with sys.modules.iteritems(), we're subject to a race
condition: if there's another thread (e.g., in scons) that does an
import, sys.modules will change while we're iterating over it.
  • Loading branch information
PaulPrice committed Jun 2, 2016
1 parent 112c08c commit 1fe6f69
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/lsst/base/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def getPythonPackages():
pass # It's not available, so don't care

packages = {"python": sys.version}
for name, module in sys.modules.iteritems():
# Not iterating with sys.modules.iteritems() because it's not atomic and subject to race conditions
moduleNames = sys.modules.keys()
for name in moduleNames:
module = sys.modules[name]
try:
ver = getVersionFromPythonModule(module)
except:
Expand Down

0 comments on commit 1fe6f69

Please sign in to comment.