Acquire the global package installation lock for this board.
(self)
| 63 | return False |
| 64 | |
| 65 | def acquire(self) -> None: |
| 66 | """Acquire the global package installation lock for this board.""" |
| 67 | if self._is_acquired: |
| 68 | return # Already acquired |
| 69 | |
| 70 | my_pid = os.getpid() |
| 71 | hostname = platform.node() |
| 72 | start_time = time.time() |
| 73 | warning_shown = False |
| 74 | last_stale_check = 0.0 |
| 75 | |
| 76 | while True: |
| 77 | # Check for keyboard interrupt |
| 78 | if is_interrupted(): |
| 79 | print( |
| 80 | f"\nKeyboardInterrupt: Aborting lock acquisition for platform {self.platform_name}" |
| 81 | ) |
| 82 | raise KeyboardInterrupt() |
| 83 | |
| 84 | elapsed = time.time() - start_time |
| 85 | |
| 86 | # Check for stale lock periodically (every ~1 second) |
| 87 | if elapsed - last_stale_check >= 1.0: |
| 88 | if self._check_stale_lock(): |
| 89 | print("Stale lock removed, retrying acquisition...") |
| 90 | last_stale_check = elapsed |
| 91 | |
| 92 | # Try to acquire |
| 93 | try: |
| 94 | success = self._db.try_acquire( |
| 95 | self._lock_name, |
| 96 | my_pid, |
| 97 | hostname, |
| 98 | f"global_package:{self.platform_name}", |
| 99 | mode="write", |
| 100 | ) |
| 101 | if success: |
| 102 | self._is_acquired = True |
| 103 | print( |
| 104 | f"Acquired global package lock for platform {self.platform_name}" |
| 105 | ) |
| 106 | return |
| 107 | except KeyboardInterrupt as ki: |
| 108 | handle_keyboard_interrupt(ki) |
| 109 | raise |
| 110 | except Exception: |
| 111 | pass # Continue the loop |
| 112 | |
| 113 | # Check if we should show warning (after 1 second) |
| 114 | if not warning_shown and elapsed >= 1.0: |
| 115 | yellow = "\033[33m" |
| 116 | reset = "\033[0m" |
| 117 | print( |
| 118 | f"{yellow}Platform {self.platform_name} is waiting to acquire global package lock{reset}" |
| 119 | ) |
| 120 | warning_shown = True |
| 121 | |
| 122 | # Check for timeout (after 5 seconds) |
no test coverage detected