summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index ebee65d3dd..67e22f4389 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -1857,12 +1857,30 @@ def path_is_descendant(descendant, ancestor):
1857# If we don't have a timeout of some kind and a process/thread exits badly (for example 1857# If we don't have a timeout of some kind and a process/thread exits badly (for example
1858# OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better 1858# OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better
1859# we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. 1859# we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked.
1860# This function can still deadlock python since it can't signal the other threads to exit
1861# (signals are handled in the main thread) and even os._exit() will wait on non-daemon threads
1862# to exit.
1860@contextmanager 1863@contextmanager
1861def lock_timeout(lock): 1864def lock_timeout(lock):
1862 held = lock.acquire(timeout=5*60)
1863 try: 1865 try:
1866 s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals())
1867 held = lock.acquire(timeout=5*60)
1864 if not held: 1868 if not held:
1869 bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack())
1865 os._exit(1) 1870 os._exit(1)
1866 yield held 1871 yield held
1867 finally: 1872 finally:
1868 lock.release() 1873 lock.release()
1874 signal.pthread_sigmask(signal.SIG_SETMASK, s)
1875
1876# A version of lock_timeout without the check that the lock was locked and a shorter timeout
1877@contextmanager
1878def lock_timeout_nocheck(lock):
1879 try:
1880 s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals())
1881 l = lock.acquire(timeout=10)
1882 yield l
1883 finally:
1884 if l:
1885 lock.release()
1886 signal.pthread_sigmask(signal.SIG_SETMASK, s)