summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/utils.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 67e22f4389..d2f11e4377 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -1854,6 +1854,15 @@ def path_is_descendant(descendant, ancestor):
1854 1854
1855 return False 1855 return False
1856 1856
1857# Recomputing the sets in signal.py is expensive (bitbake -pP idle)
1858# so try and use _signal directly to avoid it
1859valid_signals = signal.valid_signals()
1860try:
1861 import _signal
1862 sigmask = _signal.pthread_sigmask
1863except ImportError:
1864 sigmask = signal.pthread_sigmask
1865
1857# If we don't have a timeout of some kind and a process/thread exits badly (for example 1866# 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 1867# 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. 1868# we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked.
@@ -1863,7 +1872,7 @@ def path_is_descendant(descendant, ancestor):
1863@contextmanager 1872@contextmanager
1864def lock_timeout(lock): 1873def lock_timeout(lock):
1865 try: 1874 try:
1866 s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) 1875 s = sigmask(signal.SIG_BLOCK, valid_signals)
1867 held = lock.acquire(timeout=5*60) 1876 held = lock.acquire(timeout=5*60)
1868 if not held: 1877 if not held:
1869 bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) 1878 bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack())
@@ -1871,16 +1880,16 @@ def lock_timeout(lock):
1871 yield held 1880 yield held
1872 finally: 1881 finally:
1873 lock.release() 1882 lock.release()
1874 signal.pthread_sigmask(signal.SIG_SETMASK, s) 1883 sigmask(signal.SIG_SETMASK, s)
1875 1884
1876# A version of lock_timeout without the check that the lock was locked and a shorter timeout 1885# A version of lock_timeout without the check that the lock was locked and a shorter timeout
1877@contextmanager 1886@contextmanager
1878def lock_timeout_nocheck(lock): 1887def lock_timeout_nocheck(lock):
1879 try: 1888 try:
1880 s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) 1889 s = sigmask(signal.SIG_BLOCK, valid_signals)
1881 l = lock.acquire(timeout=10) 1890 l = lock.acquire(timeout=10)
1882 yield l 1891 yield l
1883 finally: 1892 finally:
1884 if l: 1893 if l:
1885 lock.release() 1894 lock.release()
1886 signal.pthread_sigmask(signal.SIG_SETMASK, s) 1895 sigmask(signal.SIG_SETMASK, s)