diff options
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py')
-rw-r--r-- | WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py b/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py index d65801d..8995b21 100644 --- a/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py +++ b/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py @@ -36,6 +36,7 @@ import tempfile import time from webkitpy.common.system.executive import Executive +from webkitpy.common.system.file_lock import FileLock _log = logging.getLogger("webkitpy.layout_tests.port.http_lock") @@ -52,10 +53,9 @@ class HttpLock(object): self._lock_file_path_prefix = os.path.join(self._lock_path, self._lock_file_prefix) self._guard_lock_file = os.path.join(self._lock_path, guard_lock) + self._guard_lock = FileLock(self._guard_lock_file) self._process_lock_file_name = "" self._executive = Executive() - # maximum wait time for the lock creation - self._guard_lock_max_wait = 1 * 60 def cleanup_http_lock(self): """Delete the lock file if exists.""" @@ -95,35 +95,31 @@ class HttpLock(object): _log.debug("Removing stuck lock file: %s" % lock_list[0]) os.unlink(lock_list[0]) return - except IOError, OSError: + except (IOError, OSError): return return int(current_pid) def _create_lock_file(self): """The lock files are used to schedule the running test sessions in first - come first served order. The sequential guard lock ensures that the lock - numbers are sequential.""" + come first served order. The guard lock ensures that the lock numbers are + sequential.""" if not os.path.exists(self._lock_path): _log.debug("Lock directory does not exist: %s" % self._lock_path) return False - start_time = time.time() - while(True): - try: - sequential_guard_lock = os.open(self._guard_lock_file, os.O_CREAT | os.O_EXCL) - self._process_lock_file_name = (self._lock_file_path_prefix + - str(self._next_lock_number())) - lock_file = open(self._process_lock_file_name, 'w') - _log.debug("Creating lock file: %s" % self._process_lock_file_name) - lock_file.write(str(os.getpid())) - lock_file.close() - os.close(sequential_guard_lock) - os.unlink(self._guard_lock_file) - return True - except OSError: - if time.time() - start_time > self._guard_lock_max_wait: - _log.debug("Lock does not created: %s" % str(sys.exc_info())) - return False + if not self._guard_lock.acquire_lock(): + _log.debug("Guard lock timed out!") + return False + + self._process_lock_file_name = (self._lock_file_path_prefix + + str(self._next_lock_number())) + _log.debug("Creating lock file: %s" % self._process_lock_file_name) + lock_file = open(self._process_lock_file_name, 'w') + lock_file.write(str(os.getpid())) + lock_file.close() + self._guard_lock.release_lock() + return True + def wait_for_httpd_lock(self): """Create a lock file and wait until it's turn comes. If something goes wrong |