diff options
Diffstat (limited to 'bitbake/lib/bb')
| -rw-r--r-- | bitbake/lib/bb/utils.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index f688f7dd68..016036dbce 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
| @@ -2226,6 +2226,15 @@ def path_is_descendant(descendant, ancestor): | |||
| 2226 | 2226 | ||
| 2227 | return False | 2227 | return False |
| 2228 | 2228 | ||
| 2229 | # Recomputing the sets in signal.py is expensive (bitbake -pP idle) | ||
| 2230 | # so try and use _signal directly to avoid it | ||
| 2231 | valid_signals = signal.valid_signals() | ||
| 2232 | try: | ||
| 2233 | import _signal | ||
| 2234 | sigmask = _signal.pthread_sigmask | ||
| 2235 | except ImportError: | ||
| 2236 | sigmask = signal.pthread_sigmask | ||
| 2237 | |||
| 2229 | # If we don't have a timeout of some kind and a process/thread exits badly (for example | 2238 | # If we don't have a timeout of some kind and a process/thread exits badly (for example |
| 2230 | # OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better | 2239 | # OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better |
| 2231 | # we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. | 2240 | # we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. |
| @@ -2235,7 +2244,7 @@ def path_is_descendant(descendant, ancestor): | |||
| 2235 | @contextmanager | 2244 | @contextmanager |
| 2236 | def lock_timeout(lock): | 2245 | def lock_timeout(lock): |
| 2237 | try: | 2246 | try: |
| 2238 | s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) | 2247 | s = sigmask(signal.SIG_BLOCK, valid_signals) |
| 2239 | held = lock.acquire(timeout=5*60) | 2248 | held = lock.acquire(timeout=5*60) |
| 2240 | if not held: | 2249 | if not held: |
| 2241 | bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) | 2250 | bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) |
| @@ -2243,17 +2252,17 @@ def lock_timeout(lock): | |||
| 2243 | yield held | 2252 | yield held |
| 2244 | finally: | 2253 | finally: |
| 2245 | lock.release() | 2254 | lock.release() |
| 2246 | signal.pthread_sigmask(signal.SIG_SETMASK, s) | 2255 | sigmask(signal.SIG_SETMASK, s) |
| 2247 | 2256 | ||
| 2248 | # A version of lock_timeout without the check that the lock was locked and a shorter timeout | 2257 | # A version of lock_timeout without the check that the lock was locked and a shorter timeout |
| 2249 | @contextmanager | 2258 | @contextmanager |
| 2250 | def lock_timeout_nocheck(lock): | 2259 | def lock_timeout_nocheck(lock): |
| 2251 | l = False | 2260 | l = False |
| 2252 | try: | 2261 | try: |
| 2253 | s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) | 2262 | s = sigmask(signal.SIG_BLOCK, valid_signals) |
| 2254 | l = lock.acquire(timeout=10) | 2263 | l = lock.acquire(timeout=10) |
| 2255 | yield l | 2264 | yield l |
| 2256 | finally: | 2265 | finally: |
| 2257 | if l: | 2266 | if l: |
| 2258 | lock.release() | 2267 | lock.release() |
| 2259 | signal.pthread_sigmask(signal.SIG_SETMASK, s) | 2268 | sigmask(signal.SIG_SETMASK, s) |
