|
@@ -5,6 +5,7 @@ import os
|
|
|
import pkgutil
|
|
import pkgutil
|
|
|
import sys
|
|
import sys
|
|
|
import traceback
|
|
import traceback
|
|
|
|
|
+import threading
|
|
|
from collections import OrderedDict
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
import yaml
|
|
import yaml
|
|
@@ -13,11 +14,9 @@ from django.conf import settings
|
|
|
from django.core.validators import RegexValidator
|
|
from django.core.validators import RegexValidator
|
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
|
from django.utils.functional import classproperty
|
|
from django.utils.functional import classproperty
|
|
|
-from django_rq import job
|
|
|
|
|
|
|
|
|
|
from extras.api.serializers import ScriptOutputSerializer
|
|
from extras.api.serializers import ScriptOutputSerializer
|
|
|
from extras.choices import JobResultStatusChoices, LogLevelChoices
|
|
from extras.choices import JobResultStatusChoices, LogLevelChoices
|
|
|
-from extras.models import JobResult
|
|
|
|
|
from ipam.formfields import IPAddressFormField, IPNetworkFormField
|
|
from ipam.formfields import IPAddressFormField, IPNetworkFormField
|
|
|
from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator
|
|
from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator
|
|
|
from utilities.exceptions import AbortTransaction
|
|
from utilities.exceptions import AbortTransaction
|
|
@@ -42,6 +41,8 @@ __all__ = [
|
|
|
'TextVar',
|
|
'TextVar',
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
+lock = threading.Lock()
|
|
|
|
|
+
|
|
|
|
|
|
|
|
#
|
|
#
|
|
|
# Script variables
|
|
# Script variables
|
|
@@ -491,11 +492,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
|
|
# Iterate through all modules within the scripts path. These are the user-created files in which reports are
|
|
|
# defined.
|
|
# defined.
|
|
|
for importer, module_name, _ in pkgutil.iter_modules([settings.SCRIPTS_ROOT]):
|
|
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'):
|
|
if use_names and hasattr(module, 'name'):
|
|
|
module_name = module.name
|
|
module_name = module.name
|
|
|
module_scripts = OrderedDict()
|
|
module_scripts = OrderedDict()
|