summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/event.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-20 14:20:22 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-12-29 00:07:06 +0000
commit907e91796ed4156cafcbd3ee60edaa9544f0abe3 (patch)
tree29c6a113f4b38ce6426ea41d0a035df45e206792 /bitbake/lib/bb/event.py
parent6549f58cd6e22b4c345212237e81e68e12dfcb61 (diff)
downloadpoky-907e91796ed4156cafcbd3ee60edaa9544f0abe3.tar.gz
bitbake: event: builtins fix for 'd' deletion
I've been seeing event handlers where 'd' seems to disappear half way through event handler execution. This is problematic when multiple threads are active since this code assumes single threading. The easiest fix is to change the handler function calls to contain d as a parameter as we do elsewhere for other functions. This will break any non-text handlers but I was only able to spot one of those in runqueue. It will also break handlers than call functions that assume 'd' is in the global namespace but those failures should be obvious and we can fix those to pass d around. This solution avoids manipulating builtins which was always a horrible thing to do anyway and solves the issue without needing locking, thankfully. (Bitbake rev: 1e12f0a4b592dacd006d370ec29cd71d2a44312e) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/event.py')
-rw-r--r--bitbake/lib/bb/event.py18
1 files changed, 4 insertions, 14 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index 97668601a1..303b7a943f 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -70,11 +70,6 @@ _uiready = False
70_thread_lock = threading.Lock() 70_thread_lock = threading.Lock()
71_thread_lock_enabled = False 71_thread_lock_enabled = False
72 72
73if hasattr(__builtins__, '__setitem__'):
74 builtins = __builtins__
75else:
76 builtins = __builtins__.__dict__
77
78def enable_threadlock(): 73def enable_threadlock():
79 global _thread_lock_enabled 74 global _thread_lock_enabled
80 _thread_lock_enabled = True 75 _thread_lock_enabled = True
@@ -85,12 +80,8 @@ def disable_threadlock():
85 80
86def execute_handler(name, handler, event, d): 81def execute_handler(name, handler, event, d):
87 event.data = d 82 event.data = d
88 addedd = False
89 if 'd' not in builtins:
90 builtins['d'] = d
91 addedd = True
92 try: 83 try:
93 ret = handler(event) 84 ret = handler(event, d)
94 except (bb.parse.SkipRecipe, bb.BBHandledException): 85 except (bb.parse.SkipRecipe, bb.BBHandledException):
95 raise 86 raise
96 except Exception: 87 except Exception:
@@ -104,8 +95,7 @@ def execute_handler(name, handler, event, d):
104 raise 95 raise
105 finally: 96 finally:
106 del event.data 97 del event.data
107 if addedd: 98
108 del builtins['d']
109 99
110def fire_class_handlers(event, d): 100def fire_class_handlers(event, d):
111 if isinstance(event, logging.LogRecord): 101 if isinstance(event, logging.LogRecord):
@@ -253,12 +243,12 @@ def register(name, handler, mask=None, filename=None, lineno=None, data=None):
253 if handler is not None: 243 if handler is not None:
254 # handle string containing python code 244 # handle string containing python code
255 if isinstance(handler, str): 245 if isinstance(handler, str):
256 tmp = "def %s(e):\n%s" % (name, handler) 246 tmp = "def %s(e, d):\n%s" % (name, handler)
257 try: 247 try:
258 code = bb.methodpool.compile_cache(tmp) 248 code = bb.methodpool.compile_cache(tmp)
259 if not code: 249 if not code:
260 if filename is None: 250 if filename is None:
261 filename = "%s(e)" % name 251 filename = "%s(e, d)" % name
262 code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST) 252 code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST)
263 if lineno is not None: 253 if lineno is not None:
264 ast.increment_lineno(code, lineno-1) 254 ast.increment_lineno(code, lineno-1)