From: "Aníbal Limón" <anibal.limon@linux.intel.com>
To: bitbake-devel@lists.openembedded.org
Cc: joshua.g.lock@intel.com, clarson@kergoth.com
Subject: [PATCHv2] bb/event.py: fire_ui_handlers enable threading lock support
Date: Tue, 4 Oct 2016 16:15:56 -0500 [thread overview]
Message-ID: <1475615756-3556-1-git-send-email-anibal.limon@linux.intel.com> (raw)
In some cases there is a need to fire bb events into multiple
python threads so locking is needed (writing to a fd/socket).
Adding a helper functions for disable/enable by request to avoid
overhead.
[YOCTO #10330]
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
---
lib/bb/event.py | 21 +++++++++++++++++++++
lib/toaster/tests/functional/README | 0
2 files changed, 21 insertions(+)
create mode 100644 lib/toaster/tests/functional/README
diff --git a/lib/bb/event.py b/lib/bb/event.py
index 42745e2..65b7ebb 100644
--- a/lib/bb/event.py
+++ b/lib/bb/event.py
@@ -29,6 +29,8 @@ import logging
import atexit
import traceback
import ast
+import threading
+
import bb.utils
import bb.compat
import bb.exceptions
@@ -68,12 +70,22 @@ _event_handler_map = {}
_catchall_handlers = {}
_eventfilter = None
_uiready = False
+_thread_lock = threading.Lock()
+_thread_lock_enabled = False
if hasattr(__builtins__, '__setitem__'):
builtins = __builtins__
else:
builtins = __builtins__.__dict__
+def enable_threadlock():
+ global _thread_lock_enabled
+ _thread_lock_enabled = True
+
+def disable_threadlock():
+ global _thread_lock_enabled
+ _thread_lock_enabled = False
+
def execute_handler(name, handler, event, d):
event.data = d
addedd = False
@@ -146,11 +158,17 @@ def print_ui_queue():
logger.handle(event)
def fire_ui_handlers(event, d):
+ global _thread_lock
+ global _thread_lock_enabled
+
if not _uiready:
# No UI handlers registered yet, queue up the messages
ui_queue.append(event)
return
+ if _thread_lock_enabled:
+ _thread_lock.acquire()
+
errors = []
for h in _ui_handlers:
#print "Sending event %s" % event
@@ -169,6 +187,9 @@ def fire_ui_handlers(event, d):
for h in errors:
del _ui_handlers[h]
+ if _thread_lock_enabled:
+ _thread_lock.release()
+
def fire(event, d):
"""Fire off an Event"""
diff --git a/lib/toaster/tests/functional/README b/lib/toaster/tests/functional/README
new file mode 100644
index 0000000..e69de29
--
2.1.4
next reply other threads:[~2016-10-04 21:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-04 21:15 Aníbal Limón [this message]
2016-10-04 21:16 ` [PATCHv2] bb/event.py: fire_ui_handlers enable threading lock support Aníbal Limón
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475615756-3556-1-git-send-email-anibal.limon@linux.intel.com \
--to=anibal.limon@linux.intel.com \
--cc=bitbake-devel@lists.openembedded.org \
--cc=clarson@kergoth.com \
--cc=joshua.g.lock@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.