diff options
| -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 5486f9599d..0832422683 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
| @@ -1876,6 +1876,15 @@ def path_is_descendant(descendant, ancestor): | |||
| 1876 | 1876 | ||
| 1877 | return False | 1877 | return False |
| 1878 | 1878 | ||
| 1879 | # Recomputing the sets in signal.py is expensive (bitbake -pP idle) | ||
| 1880 | # so try and use _signal directly to avoid it | ||
| 1881 | valid_signals = signal.valid_signals() | ||
| 1882 | try: | ||
| 1883 | import _signal | ||
| 1884 | sigmask = _signal.pthread_sigmask | ||
| 1885 | except ImportError: | ||
| 1886 | sigmask = signal.pthread_sigmask | ||
| 1887 | |||
| 1879 | # If we don't have a timeout of some kind and a process/thread exits badly (for example | 1888 | # If we don't have a timeout of some kind and a process/thread exits badly (for example |
| 1880 | # OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better | 1889 | # OOM killed) and held a lock, we'd just hang in the lock futex forever. It is better |
| 1881 | # we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. | 1890 | # we exit at some point than hang. 5 minutes with no progress means we're probably deadlocked. |
| @@ -1885,7 +1894,7 @@ def path_is_descendant(descendant, ancestor): | |||
| 1885 | @contextmanager | 1894 | @contextmanager |
| 1886 | def lock_timeout(lock): | 1895 | def lock_timeout(lock): |
| 1887 | try: | 1896 | try: |
| 1888 | s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) | 1897 | s = sigmask(signal.SIG_BLOCK, valid_signals) |
| 1889 | held = lock.acquire(timeout=5*60) | 1898 | held = lock.acquire(timeout=5*60) |
| 1890 | if not held: | 1899 | if not held: |
| 1891 | bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) | 1900 | bb.server.process.serverlog("Couldn't get the lock for 5 mins, timed out, exiting.\n%s" % traceback.format_stack()) |
| @@ -1893,16 +1902,16 @@ def lock_timeout(lock): | |||
| 1893 | yield held | 1902 | yield held |
| 1894 | finally: | 1903 | finally: |
| 1895 | lock.release() | 1904 | lock.release() |
| 1896 | signal.pthread_sigmask(signal.SIG_SETMASK, s) | 1905 | sigmask(signal.SIG_SETMASK, s) |
| 1897 | 1906 | ||
| 1898 | # A version of lock_timeout without the check that the lock was locked and a shorter timeout | 1907 | # A version of lock_timeout without the check that the lock was locked and a shorter timeout |
| 1899 | @contextmanager | 1908 | @contextmanager |
| 1900 | def lock_timeout_nocheck(lock): | 1909 | def lock_timeout_nocheck(lock): |
| 1901 | try: | 1910 | try: |
| 1902 | s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals()) | 1911 | s = sigmask(signal.SIG_BLOCK, valid_signals) |
| 1903 | l = lock.acquire(timeout=10) | 1912 | l = lock.acquire(timeout=10) |
| 1904 | yield l | 1913 | yield l |
| 1905 | finally: | 1914 | finally: |
| 1906 | if l: | 1915 | if l: |
| 1907 | lock.release() | 1916 | lock.release() |
| 1908 | signal.pthread_sigmask(signal.SIG_SETMASK, s) | 1917 | sigmask(signal.SIG_SETMASK, s) |
