diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-02-22 13:31:34 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-02-23 12:12:18 +0000 |
| commit | 42c92cbc83a56249203aeb23fe524f9b4eebbdf9 (patch) | |
| tree | b9c4dbdaacd51acdf564e684712db7ab613f1d52 /bitbake/lib/bb/event.py | |
| parent | 906657e9beef9a256b642ebb9857036710c24f62 (diff) | |
| download | poky-42c92cbc83a56249203aeb23fe524f9b4eebbdf9.tar.gz | |
bitbake: event/cooker/runqueue: Add ability to interrupt longer running code
Bitbake is now able to understand when a UI wants it to stop the current
processing. There are some long running functions which currently have no
mechanism to interrupt them however.
This patch adds a call, bb.event.check_for_interrupts(d) which can be
placed in long running code and allows an internal state flag within
bitbake to be checked. If set, that flag will trigger an exit.
This means that Ctrl+C can be made to work in a variety of places where
it currently would not.
Long running event handlers in OE-Core can also then benefit from this
new approach with the addition of the function call as well.
(Bitbake rev: b7ed7e9a815c4e10447fd499508be3dbb47f06e8)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/event.py')
| -rw-r--r-- | bitbake/lib/bb/event.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index 8b05f93e2f..37cc630c63 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py | |||
| @@ -69,6 +69,7 @@ _eventfilter = None | |||
| 69 | _uiready = False | 69 | _uiready = False |
| 70 | _thread_lock = threading.Lock() | 70 | _thread_lock = threading.Lock() |
| 71 | _heartbeat_enabled = False | 71 | _heartbeat_enabled = False |
| 72 | _should_exit = threading.Event() | ||
| 72 | 73 | ||
| 73 | def enable_threadlock(): | 74 | def enable_threadlock(): |
| 74 | # Always needed now | 75 | # Always needed now |
| @@ -86,6 +87,16 @@ def disable_heartbeat(): | |||
| 86 | global _heartbeat_enabled | 87 | global _heartbeat_enabled |
| 87 | _heartbeat_enabled = False | 88 | _heartbeat_enabled = False |
| 88 | 89 | ||
| 90 | # | ||
| 91 | # In long running code, this function should be called periodically | ||
| 92 | # to check if we should exit due to an interuption (.e.g Ctrl+C from the UI) | ||
| 93 | # | ||
| 94 | def check_for_interrupts(d): | ||
| 95 | global _should_exit | ||
| 96 | if _should_exit.is_set(): | ||
| 97 | bb.warn("Exiting due to interrupt.") | ||
| 98 | raise bb.BBHandledException() | ||
| 99 | |||
| 89 | def execute_handler(name, handler, event, d): | 100 | def execute_handler(name, handler, event, d): |
| 90 | event.data = d | 101 | event.data = d |
| 91 | try: | 102 | try: |
