diff options
Diffstat (limited to 'bitbake/lib/bb/cooker.py')
-rw-r--r-- | bitbake/lib/bb/cooker.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index d6fcd9e05c..7c0c5d4efa 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py | |||
@@ -2017,6 +2017,22 @@ class Parser(multiprocessing.Process): | |||
2017 | self.context = bb.utils.get_context().copy() | 2017 | self.context = bb.utils.get_context().copy() |
2018 | self.handlers = bb.event.get_class_handlers().copy() | 2018 | self.handlers = bb.event.get_class_handlers().copy() |
2019 | self.profile = profile | 2019 | self.profile = profile |
2020 | self.queue_signals = False | ||
2021 | self.signal_received = [] | ||
2022 | self.signal_threadlock = threading.Lock() | ||
2023 | |||
2024 | def catch_sig(self, signum, frame): | ||
2025 | if self.queue_signals: | ||
2026 | self.signal_received.append(signum) | ||
2027 | else: | ||
2028 | self.handle_sig(signum, frame) | ||
2029 | |||
2030 | def handle_sig(self, signum, frame): | ||
2031 | if signum == signal.SIGTERM: | ||
2032 | signal.signal(signal.SIGTERM, signal.SIG_DFL) | ||
2033 | os.kill(os.getpid(), signal.SIGTERM) | ||
2034 | elif signum == signal.SIGINT: | ||
2035 | signal.default_int_handler(signum, frame) | ||
2020 | 2036 | ||
2021 | def run(self): | 2037 | def run(self): |
2022 | 2038 | ||
@@ -2036,9 +2052,17 @@ class Parser(multiprocessing.Process): | |||
2036 | prof.dump_stats(logfile) | 2052 | prof.dump_stats(logfile) |
2037 | 2053 | ||
2038 | def realrun(self): | 2054 | def realrun(self): |
2039 | signal.signal(signal.SIGTERM, signal.SIG_DFL) | 2055 | # Signal handling here is hard. We must not terminate any process or thread holding the write |
2056 | # lock for the event stream as it will not be released, ever, and things will hang. | ||
2057 | # Python handles signals in the main thread/process but they can be raised from any thread and | ||
2058 | # we want to defer processing of any SIGTERM/SIGINT signal until we're outside the critical section | ||
2059 | # and don't hold the lock (see server/process.py). We therefore always catch the signals (so any | ||
2060 | # new thread should also do so) and we defer handling but we handle with the local thread lock | ||
2061 | # held (a threading lock, not a multiprocessing one) so that no other thread in the process | ||
2062 | # can be in the critical section. | ||
2063 | signal.signal(signal.SIGTERM, self.catch_sig) | ||
2040 | signal.signal(signal.SIGHUP, signal.SIG_DFL) | 2064 | signal.signal(signal.SIGHUP, signal.SIG_DFL) |
2041 | signal.signal(signal.SIGINT, signal.SIG_IGN) | 2065 | signal.signal(signal.SIGINT, self.catch_sig) |
2042 | bb.utils.set_process_name(multiprocessing.current_process().name) | 2066 | bb.utils.set_process_name(multiprocessing.current_process().name) |
2043 | multiprocessing.util.Finalize(None, bb.codeparser.parser_cache_save, exitpriority=1) | 2067 | multiprocessing.util.Finalize(None, bb.codeparser.parser_cache_save, exitpriority=1) |
2044 | multiprocessing.util.Finalize(None, bb.fetch.fetcher_parse_save, exitpriority=1) | 2068 | multiprocessing.util.Finalize(None, bb.fetch.fetcher_parse_save, exitpriority=1) |