Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions netbox/extras/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pkgutil
import sys
import traceback
import threading
from collections import OrderedDict

import yaml
Expand Down Expand Up @@ -42,6 +43,8 @@
'TextVar',
]

lock = threading.Lock()


#
# Script variables
Expand Down Expand Up @@ -491,11 +494,14 @@ def get_scripts(use_names=False):
# Iterate through all modules within the scripts path. These are the user-created files in which reports are
# defined.
for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
# Remove cached module to ensure consistency with filesystem
if module_name in sys.modules:
del sys.modules[module_name]
# Use a lock as removing and loading modules is not thread safe
with lock:
# Remove cached module to ensure consistency with filesystem
if module_name in sys.modules:
del sys.modules[module_name]

module = importer.find_module(module_name).load_module(module_name)

module = importer.find_module(module_name).load_module(module_name)
if use_names and hasattr(module, 'name'):
module_name = module.name
module_scripts = OrderedDict()
Expand Down