本文整理汇总了Python中webkitpy.common.system.executive.Executive.check_running_pid方法的典型用法代码示例。如果您正苦于以下问题:Python Executive.check_running_pid方法的具体用法?Python Executive.check_running_pid怎么用?Python Executive.check_running_pid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webkitpy.common.system.executive.Executive
的用法示例。
在下文中一共展示了Executive.check_running_pid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_check_running_pid
# 需要导入模块: from webkitpy.common.system.executive import Executive [as 别名]
# 或者: from webkitpy.common.system.executive.Executive import check_running_pid [as 别名]
def test_check_running_pid(self):
executive = Executive()
self.assertTrue(executive.check_running_pid(os.getpid()))
# According to the proc(5) man page, on 64-bit linux systems,
# pid_max can be set to any value up to 2^22 (approximately 4 million).
self.assertFalse(executive.check_running_pid(5000000))
示例2: test_check_running_pid
# 需要导入模块: from webkitpy.common.system.executive import Executive [as 别名]
# 或者: from webkitpy.common.system.executive.Executive import check_running_pid [as 别名]
def test_check_running_pid(self):
executive = Executive()
self.assertTrue(executive.check_running_pid(os.getpid()))
# Maximum pid number on Linux is 32768 by default
self.assertFalse(executive.check_running_pid(100000))
示例3: HttpLock
# 需要导入模块: from webkitpy.common.system.executive import Executive [as 别名]
# 或者: from webkitpy.common.system.executive.Executive import check_running_pid [as 别名]
class HttpLock(object):
def __init__(self, lock_path, lock_file_prefix="WebKitHttpd.lock.",
guard_lock="WebKit.lock"):
self._lock_path = lock_path
if not self._lock_path:
self._lock_path = tempfile.gettempdir()
self._lock_file_prefix = lock_file_prefix
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()
def cleanup_http_lock(self):
"""Delete the lock file if exists."""
if os.path.exists(self._process_lock_file_name):
_log.debug("Removing lock file: %s" % self._process_lock_file_name)
os.unlink(self._process_lock_file_name)
def _extract_lock_number(self, lock_file_name):
"""Return the lock number from lock file."""
prefix_length = len(self._lock_file_path_prefix)
return int(lock_file_name[prefix_length:])
def _lock_file_list(self):
"""Return the list of lock files sequentially."""
lock_list = glob.glob(self._lock_file_path_prefix + '*')
lock_list.sort(key=self._extract_lock_number)
return lock_list
def _next_lock_number(self):
"""Return the next available lock number."""
lock_list = self._lock_file_list()
if not lock_list:
return 0
return self._extract_lock_number(lock_list[-1]) + 1
def _curent_lock_pid(self):
"""Return with the current lock pid. If the lock is not valid
it deletes the lock file."""
lock_list = self._lock_file_list()
if not lock_list:
return
try:
current_lock_file = open(lock_list[0], 'r')
current_pid = current_lock_file.readline()
current_lock_file.close()
if not (current_pid and self._executive.check_running_pid(int(current_pid))):
_log.debug("Removing stuck lock file: %s" % lock_list[0])
os.unlink(lock_list[0])
return
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 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
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
it wont do any locking."""
if not self._create_lock_file():
_log.debug("Warning, http locking failed!")
return
while self._curent_lock_pid() != os.getpid():
time.sleep(1)