python.d: thread safe safe_print (stdout write) (#9508)
Ilya Mashchenko committed
Jul 9, 2020 at 15:31 UTC
b9f9d8f771a03d5f246cba23719585d0ebc90fae
1 file changed
+6
collectors/python.d.plugin/python_modules/bases/collection.py
+6
@@ -5,6 +5,8 @@
5
6
import os
7
8
+from threading import Lock
9
+
10
PATH = os.getenv('PATH', '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin').split(':')
11
12
CHART_BEGIN = 'BEGIN {0} {1}\n'
@@ -12,6 +14,8 @@ CHART_CREATE = "CHART {0} '{1}' '{2}' '{3}' '{4}' '{5}' {6} {7} {8}\n"
14
DIMENSION_CREATE = "DIMENSION '{0}' '{1}' {2} {3} {4} '{5}'\n"
15
DIMENSION_SET = "SET '{0}' = {1}\n"
16
17
+print_lock = Lock()
18
+
19
20
def setdefault_values(config, base_dict):
21
for key, value in base_dict.items():
@@ -62,7 +66,9 @@ def safe_print(*msg):
66
:param msg:
67
:return:
68
"""
69
+ print_lock.acquire()
70
print(''.join(msg))
71
+ print_lock.release()
72
73
74
def find_binary(binary):