Skip to content

Commit

Permalink
Defaults.py: avoid RuntimeError when loading worker modules
Browse files Browse the repository at this point in the history
Iterating directly over sys.modules is not thread-safe.

Closes #304.

Change-Id: I92b5f211cd31053f5c70807589aac799722d4c26
  • Loading branch information
thiell committed Apr 29, 2016
1 parent d8f9e1e commit 7392639
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/ClusterShell/Defaults.py
@@ -1,5 +1,5 @@
#
# Copyright 2015 Stephane Thiell <sthiell@stanford.edu>
# Copyright 2015-2016 Stephane Thiell <sthiell@stanford.edu>
#
# This file is part of the ClusterShell library.
#
Expand Down Expand Up @@ -63,8 +63,9 @@ def _load_workerclass(workername):
"""
modname = "ClusterShell.Worker.%s" % workername.capitalize()

# Import module if not yet loaded
if modname.lower() not in [mod.lower() for mod in sys.modules]:
# Do not iterate over sys.modules but use .keys() to avoid RuntimeError
if modname.lower() not in [mod.lower() for mod in sys.modules.keys()]:
# Import module if not yet loaded
__import__(modname)

# Get the class pointer
Expand All @@ -80,8 +81,7 @@ def _distant_workerclass(defaults):

def config_paths(config_name):
"""Return default path list for a ClusterShell config file name."""
return [# system-wide config file
'/etc/clustershell/%s' % config_name,
return ['/etc/clustershell/%s' % config_name, # system-wide config file
# default pip --user config file
os.path.expanduser('~/.local/etc/clustershell/%s' % config_name),
# per-user config (top override)
Expand Down

0 comments on commit 7392639

Please sign in to comment.