本文整理汇总了Python中_emerge.AsynchronousLock.AsynchronousLock.addExitListener方法的典型用法代码示例。如果您正苦于以下问题:Python AsynchronousLock.addExitListener方法的具体用法?Python AsynchronousLock.addExitListener怎么用?Python AsynchronousLock.addExitListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_emerge.AsynchronousLock.AsynchronousLock
的用法示例。
在下文中一共展示了AsynchronousLock.addExitListener方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _BinpkgFetcherProcess
# 需要导入模块: from _emerge.AsynchronousLock import AsynchronousLock [as 别名]
# 或者: from _emerge.AsynchronousLock.AsynchronousLock import addExitListener [as 别名]
#.........这里部分代码省略.........
fcmd_vars[k] = v
fetch_env = dict(settings.items())
fetch_args = [portage.util.varexpand(x, mydict=fcmd_vars) \
for x in portage.util.shlex_split(fcmd)]
if self.fd_pipes is None:
self.fd_pipes = {}
fd_pipes = self.fd_pipes
# Redirect all output to stdout since some fetchers like
# wget pollute stderr (if portage detects a problem then it
# can send it's own message to stderr).
fd_pipes.setdefault(0, portage._get_stdin().fileno())
fd_pipes.setdefault(1, sys.__stdout__.fileno())
fd_pipes.setdefault(2, sys.__stdout__.fileno())
self.args = fetch_args
self.env = fetch_env
if settings.selinux_enabled():
self._selinux_type = settings["PORTAGE_FETCH_T"]
SpawnProcess._start(self)
def _pipe(self, fd_pipes):
"""When appropriate, use a pty so that fetcher progress bars,
like wget has, will work properly."""
if self.background or not sys.__stdout__.isatty():
# When the output only goes to a log file,
# there's no point in creating a pty.
return os.pipe()
stdout_pipe = None
if not self.background:
stdout_pipe = fd_pipes.get(1)
got_pty, master_fd, slave_fd = \
_create_pty_or_pipe(copy_term_size=stdout_pipe)
return (master_fd, slave_fd)
def sync_timestamp(self):
# If possible, update the mtime to match the remote package if
# the fetcher didn't already do it automatically.
bintree = self.pkg.root_config.trees["bintree"]
if bintree._remote_has_index:
remote_mtime = bintree._remotepkgs[
bintree.dbapi._instance_key(
self.pkg.cpv)].get("_mtime_")
if remote_mtime is not None:
try:
remote_mtime = long(remote_mtime)
except ValueError:
pass
else:
try:
local_mtime = os.stat(self.pkg_path)[stat.ST_MTIME]
except OSError:
pass
else:
if remote_mtime != local_mtime:
try:
os.utime(self.pkg_path,
(remote_mtime, remote_mtime))
except OSError:
pass
def async_lock(self):
"""
This raises an AlreadyLocked exception if lock() is called
while a lock is already held. In order to avoid this, call
unlock() or check whether the "locked" attribute is True
or False before calling lock().
"""
if self._lock_obj is not None:
raise self.AlreadyLocked((self._lock_obj,))
result = self.scheduler.create_future()
def acquired_lock(async_lock):
if async_lock.wait() == os.EX_OK:
self.locked = True
result.set_result(None)
else:
result.set_exception(AssertionError(
"AsynchronousLock failed with returncode %s"
% (async_lock.returncode,)))
self._lock_obj = AsynchronousLock(path=self.pkg_path,
scheduler=self.scheduler)
self._lock_obj.addExitListener(acquired_lock)
self._lock_obj.start()
return result
class AlreadyLocked(portage.exception.PortageException):
pass
def async_unlock(self):
if self._lock_obj is None:
raise AssertionError('already unlocked')
result = self._lock_obj.async_unlock()
self._lock_obj = None
self.locked = False
return result