Skip to content

Commit 142d7c4

Browse files
authored
Merge pull request #211 from StackStorm/thread-safe
Lock global vars during initialization for thread safety
2 parents ed694d3 + 7ba1993 commit 142d7c4

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
In Progress
5+
-----------
6+
7+
Fixed
8+
~~~~~
9+
10+
* Warn users when there is a loop and no start task identified. (bug fix)
11+
* Lock global variables during initialization to make them thread safe. (bug fix)
12+
413
1.1.1
514
-----
615

orquesta/expressions/base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import logging
1818
import re
1919
import six
20+
import threading
2021

2122
from stevedore import extension
2223

@@ -27,6 +28,7 @@
2728
LOG = logging.getLogger(__name__)
2829

2930
_EXP_EVALUATORS = None
31+
_EXP_EVALUATORS_LOCK = threading.Lock()
3032
_EXP_EVALUATOR_NAMESPACE = "orquesta.expressions.evaluators"
3133

3234

@@ -73,14 +75,18 @@ def get_evaluator(language):
7375

7476
def get_evaluators():
7577
global _EXP_EVALUATORS
78+
global _EXP_EVALUATORS_LOCK
7679

77-
if _EXP_EVALUATORS is None:
78-
_EXP_EVALUATORS = {}
80+
with _EXP_EVALUATORS_LOCK:
81+
if _EXP_EVALUATORS is None:
82+
_EXP_EVALUATORS = {}
7983

80-
mgr = extension.ExtensionManager(namespace=_EXP_EVALUATOR_NAMESPACE, invoke_on_load=False)
84+
mgr = extension.ExtensionManager(
85+
namespace=_EXP_EVALUATOR_NAMESPACE, invoke_on_load=False
86+
)
8187

82-
for name in mgr.names():
83-
_EXP_EVALUATORS[name] = get_evaluator(name)
88+
for name in mgr.names():
89+
_EXP_EVALUATORS[name] = get_evaluator(name)
8490

8591
return _EXP_EVALUATORS
8692

orquesta/expressions/functions/base.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import threading
16+
1517
from stevedore import extension
1618

1719

1820
_EXP_FUNC_CATALOG = None
21+
_EXP_FUNC_CATALOG_LOCK = threading.Lock()
1922

2023

2124
def load():
2225
global _EXP_FUNC_CATALOG
26+
global _EXP_FUNC_CATALOG_LOCK
2327

24-
if _EXP_FUNC_CATALOG is None:
25-
_EXP_FUNC_CATALOG = {}
28+
with _EXP_FUNC_CATALOG_LOCK:
29+
if _EXP_FUNC_CATALOG is None:
30+
_EXP_FUNC_CATALOG = {}
2631

27-
mgr = extension.ExtensionManager(
28-
namespace="orquesta.expressions.functions", invoke_on_load=False
29-
)
32+
mgr = extension.ExtensionManager(
33+
namespace="orquesta.expressions.functions", invoke_on_load=False
34+
)
3035

31-
for name in mgr.names():
32-
_EXP_FUNC_CATALOG[name] = mgr[name].plugin
36+
for name in mgr.names():
37+
_EXP_FUNC_CATALOG[name] = mgr[name].plugin
3338

3439
return _EXP_FUNC_CATALOG

0 commit comments

Comments
 (0)