本文整理汇总了Python中portage.os.getpid函数的典型用法代码示例。如果您正苦于以下问题:Python getpid函数的具体用法?Python getpid怎么用?Python getpid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getpid函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, filename, mode='w', follow_links=True, **kargs):
"""Opens a temporary filename.pid in the same directory as filename."""
ObjectProxy.__init__(self)
object.__setattr__(self, '_aborted', False)
if 'b' in mode:
open_func = open
else:
open_func = codecs.open
kargs.setdefault('encoding', _encodings['content'])
kargs.setdefault('errors', 'backslashreplace')
if follow_links:
canonical_path = os.path.realpath(filename)
object.__setattr__(self, '_real_name', canonical_path)
tmp_name = "%s.%i" % (canonical_path, os.getpid())
try:
object.__setattr__(self, '_file',
open_func(_unicode_encode(tmp_name,
encoding=_encodings['fs'], errors='strict'),
mode=mode, **kargs))
return
except IOError as e:
if canonical_path == filename:
raise
writemsg(_("!!! Failed to open file: '%s'\n") % tmp_name,
noiselevel=-1)
writemsg("!!! %s\n" % str(e), noiselevel=-1)
object.__setattr__(self, '_real_name', filename)
tmp_name = "%s.%i" % (filename, os.getpid())
object.__setattr__(self, '_file',
open_func(_unicode_encode(tmp_name,
encoding=_encodings['fs'], errors='strict'),
mode=mode, **kargs))
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:34,代码来源:__init__.py
示例2: __init__
def __init__(self, filename, mode='w', follow_links=True, **kargs):
"""Opens a temporary filename.pid in the same directory as filename."""
ObjectProxy.__init__(self)
object.__setattr__(self, '_aborted', False)
if 'b' in mode:
open_func = open
else:
open_func = io.open
kargs.setdefault('encoding', _encodings['content'])
kargs.setdefault('errors', 'backslashreplace')
if follow_links:
canonical_path = os.path.realpath(filename)
object.__setattr__(self, '_real_name', canonical_path)
tmp_name = "%s.%i" % (canonical_path, os.getpid())
try:
object.__setattr__(self, '_file',
open_func(_unicode_encode(tmp_name,
encoding=_encodings['fs'], errors='strict'),
mode=mode, **kargs))
return
except IOError as e:
if canonical_path == filename:
raise
# Ignore this error, since it's irrelevant
# and the below open call will produce a
# new error if necessary.
object.__setattr__(self, '_real_name', filename)
tmp_name = "%s.%i" % (filename, os.getpid())
object.__setattr__(self, '_file',
open_func(_unicode_encode(tmp_name,
encoding=_encodings['fs'], errors='strict'),
mode=mode, **kargs))
开发者ID:clickbeetle,项目名称:portage-cb,代码行数:34,代码来源:__init__.py
示例3: _spawn
def _spawn(self, args, fd_pipes=None, **kwargs):
"""
Fork a subprocess, apply local settings, and call fetch().
"""
parent_pid = os.getpid()
pid = None
try:
pid = os.fork()
if pid != 0:
if not isinstance(pid, int):
raise AssertionError(
"fork returned non-integer: %s" % (repr(pid),))
return [pid]
rval = 1
try:
# Use default signal handlers in order to avoid problems
# killing subprocesses as reported in bug #353239.
signal.signal(signal.SIGINT, signal.SIG_DFL)
signal.signal(signal.SIGTERM, signal.SIG_DFL)
# Unregister SIGCHLD handler and wakeup_fd for the parent
# process's event loop (bug 655656).
signal.signal(signal.SIGCHLD, signal.SIG_DFL)
try:
wakeup_fd = signal.set_wakeup_fd(-1)
if wakeup_fd > 0:
os.close(wakeup_fd)
except (ValueError, OSError):
pass
portage.locks._close_fds()
# We don't exec, so use close_fds=False
# (see _setup_pipes docstring).
portage.process._setup_pipes(fd_pipes, close_fds=False)
rval = self._run()
except SystemExit:
raise
except:
traceback.print_exc()
# os._exit() skips stderr flush!
sys.stderr.flush()
finally:
os._exit(rval)
finally:
if pid == 0 or (pid is None and os.getpid() != parent_pid):
# Call os._exit() from a finally block in order
# to suppress any finally blocks from earlier
# in the call stack (see bug #345289). This
# finally block has to be setup before the fork
# in order to avoid a race condition.
os._exit(1)
开发者ID:gentoo,项目名称:portage,代码行数:57,代码来源:ForkProcess.py
示例4: recompose_mem
def recompose_mem(self, xpdata, break_hardlinks=True):
"""
Update the xpak segment.
@param xpdata: A new xpak segment to be written, like that returned
from the xpak_mem() function.
@param break_hardlinks: If hardlinks exist, create a copy in order
to break them. This makes it safe to use hardlinks to create
cheap snapshots of the repository, which is useful for solving
race conditions on binhosts as described here:
https://crbug.com/185031
Default is True.
"""
self.scan() # Don't care about condition... We'll rewrite the data anyway.
if break_hardlinks and self.filestat and self.filestat.st_nlink > 1:
tmp_fname = "%s.%d" % (self.file, os.getpid())
shutil.copyfile(self.file, tmp_fname)
try:
portage.util.apply_stat_permissions(self.file, self.filestat)
except portage.exception.OperationNotPermitted:
pass
os.rename(tmp_fname, self.file)
myfile = open(_unicode_encode(self.file,
encoding=_encodings['fs'], errors='strict'), 'ab+')
if not myfile:
raise IOError
myfile.seek(-self.xpaksize, 2) # 0,2 or -0,2 just mean EOF.
myfile.truncate()
myfile.write(xpdata + encodeint(len(xpdata)) + b'STOP')
myfile.flush()
myfile.close()
return 1
开发者ID:amadio,项目名称:portage,代码行数:33,代码来源:xpak.py
示例5: _hardlink_atomic
def _hardlink_atomic(self, src, dest, dir_info):
head, tail = os.path.split(dest)
hardlink_tmp = os.path.join(head, ".%s._mirrordist_hardlink_.%s" % \
(tail, os.getpid()))
try:
try:
os.link(src, hardlink_tmp)
except OSError as e:
if e.errno != errno.EXDEV:
msg = "hardlink %s from %s failed: %s" % \
(self.distfile, dir_info, e)
self.scheduler.output(msg + '\n', background=True,
log_path=self._log_path)
logging.error(msg)
return False
try:
os.rename(hardlink_tmp, dest)
except OSError as e:
msg = "hardlink rename '%s' from %s failed: %s" % \
(self.distfile, dir_info, e)
self.scheduler.output(msg + '\n', background=True,
log_path=self._log_path)
logging.error(msg)
return False
finally:
try:
os.unlink(hardlink_tmp)
except OSError:
pass
return True
开发者ID:amadio,项目名称:portage,代码行数:34,代码来源:FetchTask.py
示例6: _setitem
def _setitem(self, cpv, values):
s = cpv.rfind("/")
fp=os.path.join(self.location,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
try:
myf = codecs.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
except (OSError, IOError) as e:
if errno.ENOENT == e.errno:
try:
self._ensure_dirs(cpv)
myf = codecs.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
except (OSError, IOError) as e:
raise cache_errors.CacheCorruption(cpv, e)
else:
raise cache_errors.CacheCorruption(cpv, e)
for x in self.auxdbkey_order:
myf.write(values.get(x,"")+"\n")
myf.close()
self._ensure_access(fp, mtime=values["_mtime_"])
#update written. now we move it.
new_fp = os.path.join(self.location,cpv)
try:
os.rename(fp, new_fp)
except (OSError, IOError) as e:
os.remove(fp)
raise cache_errors.CacheCorruption(cpv, e)
开发者ID:TommyD,项目名称:gentoo-portage-multilib,代码行数:34,代码来源:flat_list.py
示例7: process
def process(mysettings, key, logentries, fulltext):
global _items
time_str = _unicode_decode(
time.strftime("%Y%m%d-%H%M%S %Z", time.localtime(time.time())), encoding=_encodings["content"], errors="replace"
)
header = _(">>> Messages generated for package %(pkg)s by process %(pid)d on %(time)s:\n\n") % {
"pkg": key,
"pid": os.getpid(),
"time": time_str,
}
config_root = mysettings["PORTAGE_CONFIGROOT"]
# Copy needed variables from the config instance,
# since we don't need to hold a reference for the
# whole thing. This also makes it possible to
# rely on per-package variable settings that may
# have come from /etc/portage/package.env, since
# we'll be isolated from any future mutations of
# mysettings.
config_dict = {}
for k in _config_keys:
v = mysettings.get(k)
if v is not None:
config_dict[k] = v
config_dict, items = _items.setdefault(config_root, (config_dict, {}))
items[key] = header + fulltext
开发者ID:lucianposton,项目名称:portage,代码行数:27,代码来源:mod_mail_summary.py
示例8: process
def process(mysettings, key, logentries, fulltext):
if mysettings["PORT_LOGDIR"] != "":
elogdir = os.path.join(mysettings["PORT_LOGDIR"], "elog")
else:
elogdir = os.path.join(os.sep, "var", "log", "portage", "elog")
ensure_dirs(elogdir, uid=portage_uid, gid=portage_gid, mode=0o2770)
# TODO: Locking
elogfilename = elogdir+"/summary.log"
elogfile = codecs.open(_unicode_encode(elogfilename,
encoding=_encodings['fs'], errors='strict'),
mode='a', encoding=_encodings['content'], errors='backslashreplace')
apply_permissions(elogfilename, mode=0o60, mask=0)
time_str = time.strftime("%Y-%m-%d %H:%M:%S %Z",
time.localtime(time.time()))
# Avoid potential UnicodeDecodeError later.
time_str = _unicode_decode(time_str,
encoding=_encodings['content'], errors='replace')
elogfile.write(_(">>> Messages generated by process %(pid)d on %(time)s for package %(pkg)s:\n\n") %
{"pid": os.getpid(), "time": time_str, "pkg": key})
elogfile.write(fulltext)
elogfile.write("\n")
elogfile.close()
return elogfilename
开发者ID:TommyD,项目名称:gentoo-portage-multilib,代码行数:25,代码来源:mod_save_summary.py
示例9: _spawn
def _spawn(self, args, fd_pipes=None, **kwargs):
"""
Fork a subprocess, apply local settings, and call fetch().
"""
parent_pid = os.getpid()
pid = None
try:
pid = os.fork()
if pid != 0:
if not isinstance(pid, int):
raise AssertionError(
"fork returned non-integer: %s" % (repr(pid),))
portage.process.spawned_pids.append(pid)
return [pid]
rval = 1
try:
# Use default signal handlers in order to avoid problems
# killing subprocesses as reported in bug #353239.
signal.signal(signal.SIGINT, signal.SIG_DFL)
signal.signal(signal.SIGTERM, signal.SIG_DFL)
portage.locks._close_fds()
# We don't exec, so use close_fds=False
# (see _setup_pipes docstring).
portage.process._setup_pipes(fd_pipes, close_fds=False)
rval = self._run()
except SystemExit:
raise
except:
traceback.print_exc()
finally:
os._exit(rval)
finally:
if pid == 0 or (pid is None and os.getpid() != parent_pid):
# Call os._exit() from a finally block in order
# to suppress any finally blocks from earlier
# in the call stack (see bug #345289). This
# finally block has to be setup before the fork
# in order to avoid a race condition.
os._exit(1)
开发者ID:clickbeetle,项目名称:portage-cb,代码行数:46,代码来源:ForkProcess.py
示例10: process
def process(mysettings, key, logentries, fulltext):
if mysettings.get("PORT_LOGDIR"):
logdir = normalize_path(mysettings["PORT_LOGDIR"])
else:
logdir = os.path.join(os.sep, mysettings["EPREFIX"].lstrip(os.sep),
"var", "log", "portage")
if not os.path.isdir(logdir):
# Only initialize group/mode if the directory doesn't
# exist, so that we don't override permissions if they
# were previously set by the administrator.
# NOTE: These permissions should be compatible with our
# default logrotate config as discussed in bug 374287.
logdir_uid = -1
if portage.data.secpass >= 2:
logdir_uid = portage_uid
ensure_dirs(logdir, uid=logdir_uid, gid=portage_gid, mode=0o2770)
elogdir = os.path.join(logdir, "elog")
_ensure_log_subdirs(logdir, elogdir)
# TODO: Locking
elogfilename = elogdir+"/summary.log"
elogfile = io.open(_unicode_encode(elogfilename,
encoding=_encodings['fs'], errors='strict'),
mode='a', encoding=_encodings['content'], errors='backslashreplace')
# Copy group permission bits from parent directory.
elogdir_st = os.stat(elogdir)
elogdir_gid = elogdir_st.st_gid
elogdir_grp_mode = 0o060 & elogdir_st.st_mode
# Copy the uid from the parent directory if we have privileges
# to do so, for compatibility with our default logrotate
# config (see bug 378451). With the "su portage portage"
# directive and logrotate-3.8.0, logrotate's chown call during
# the compression phase will only succeed if the log file's uid
# is portage_uid.
logfile_uid = -1
if portage.data.secpass >= 2:
logfile_uid = elogdir_st.st_uid
apply_permissions(elogfilename, uid=logfile_uid, gid=elogdir_gid,
mode=elogdir_grp_mode, mask=0)
time_str = time.strftime("%Y-%m-%d %H:%M:%S %Z",
time.localtime(time.time()))
# Avoid potential UnicodeDecodeError later.
time_str = _unicode_decode(time_str,
encoding=_encodings['content'], errors='replace')
elogfile.write(_unicode_decode(
_(">>> Messages generated by process " +
"%(pid)d on %(time)s for package %(pkg)s:\n\n") %
{"pid": os.getpid(), "time": time_str, "pkg": key}))
elogfile.write(_unicode_decode(fulltext))
elogfile.write(_unicode_decode("\n"))
elogfile.close()
return elogfilename
开发者ID:Acidburn0zzz,项目名称:portage-funtoo,代码行数:58,代码来源:mod_save_summary.py
示例11: process
def process(mysettings, key, logentries, fulltext):
global _items
time_str = _unicode_decode(
time.strftime("%Y%m%d-%H%M%S %Z", time.localtime(time.time())),
encoding=_encodings['content'], errors='replace')
header = _(">>> Messages generated for package %(pkg)s by process %(pid)d on %(time)s:\n\n") % \
{"pkg": key, "pid": os.getpid(), "time": time_str}
config_root = mysettings["PORTAGE_CONFIGROOT"]
mysettings, items = _items.setdefault(config_root, (mysettings, {}))
items[key] = header + fulltext
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:10,代码来源:mod_mail_summary.py
示例12: __init__
def __init__(self, environment):
self.conf = environment
pidfile = open(self.conf.get('pid_file'), 'w')
if (self.conf.get('no_daemon') == False):
print "forking to background"
if (os.fork() == 0):
os.setpgid(0,0);
pidfile.write(str(os.getpid()));
pidfile.close();
fd = os.open("/dev/null", os.O_WRONLY);
os.dup2(fd,1);
os.close(fd);
#self.main_loop()
else:
sys.exit()
else:
print "Keeping in foreground"
pidfile.write(str(os.getpid()));
pidfile.close();
开发者ID:kev40293,项目名称:portupd,代码行数:21,代码来源:portupd.py
示例13: _start
def _start(self):
pkg = self.pkg
root_config = pkg.root_config
bintree = root_config.trees["bintree"]
binpkg_tmpfile = os.path.join(bintree.pkgdir,
pkg.cpv + ".tbz2." + str(os.getpid()))
bintree._ensure_dir(os.path.dirname(binpkg_tmpfile))
self._binpkg_tmpfile = binpkg_tmpfile
self.settings["PORTAGE_BINPKG_TMPFILE"] = self._binpkg_tmpfile
package_phase = EbuildPhase(background=self.background,
phase='package', scheduler=self.scheduler,
settings=self.settings)
self._start_task(package_phase, self._package_phase_exit)
开发者ID:aeroniero33,项目名称:portage,代码行数:16,代码来源:EbuildBinpkg.py
示例14: _setitem
def _setitem(self, cpv, values):
s = cpv.rfind("/")
fp = os.path.join(self.location, cpv[:s], ".update.%i.%s" % (os.getpid(), cpv[s + 1 :]))
try:
myf = io.open(
_unicode_encode(fp, encoding=_encodings["fs"], errors="strict"),
mode="w",
encoding=_encodings["repo.content"],
errors="backslashreplace",
)
except (IOError, OSError) as e:
if errno.ENOENT == e.errno:
try:
self._ensure_dirs(cpv)
myf = io.open(
_unicode_encode(fp, encoding=_encodings["fs"], errors="strict"),
mode="w",
encoding=_encodings["repo.content"],
errors="backslashreplace",
)
except (OSError, IOError) as e:
raise cache_errors.CacheCorruption(cpv, e)
else:
raise cache_errors.CacheCorruption(cpv, e)
try:
for k in self._write_keys:
v = values.get(k)
if not v:
continue
# NOTE: This format string requires unicode_literals, so that
# k and v are coerced to unicode, in order to prevent TypeError
# when writing raw bytes to TextIOWrapper with Python 2.
myf.write("%s=%s\n" % (k, v))
finally:
myf.close()
self._ensure_access(fp)
# update written. now we move it.
new_fp = os.path.join(self.location, cpv)
try:
os.rename(fp, new_fp)
except (OSError, IOError) as e:
os.remove(fp)
raise cache_errors.CacheCorruption(cpv, e)
开发者ID:TriadicTek,项目名称:Portage,代码行数:46,代码来源:flat_hash.py
示例15: _finalize
def _finalize(mysettings, items):
if len(items) == 0:
return
elif len(items) == 1:
count = _("one package")
else:
count = _("multiple packages")
if "PORTAGE_ELOG_MAILURI" in mysettings:
myrecipient = mysettings["PORTAGE_ELOG_MAILURI"].split()[0]
else:
myrecipient = "[email protected]"
myfrom = mysettings["PORTAGE_ELOG_MAILFROM"]
myfrom = myfrom.replace("${HOST}", socket.getfqdn())
mysubject = mysettings["PORTAGE_ELOG_MAILSUBJECT"]
mysubject = mysubject.replace("${PACKAGE}", count)
mysubject = mysubject.replace("${HOST}", socket.getfqdn())
mybody = _("elog messages for the following packages generated by "
"process %(pid)d on host %(host)s:\n") % {"pid": os.getpid(), "host": socket.getfqdn()}
for key in items:
mybody += "- %s\n" % key
mymessage = portage.mail.create_message(myfrom, myrecipient, mysubject,
mybody, attachments=list(items.values()))
def timeout_handler(signum, frame):
raise PortageException("Timeout in finalize() for elog system 'mail_summary'")
import signal
signal.signal(signal.SIGALRM, timeout_handler)
# Timeout after one minute in case send_mail() blocks indefinitely.
signal.alarm(60)
try:
try:
portage.mail.send_mail(mysettings, mymessage)
finally:
signal.alarm(0)
except PortageException as e:
writemsg("%s\n" % str(e), noiselevel=-1)
return
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:42,代码来源:mod_mail_summary.py
示例16: _setitem
def _setitem(self, cpv, values):
# import pdb;pdb.set_trace()
s = cpv.rfind("/")
fp = os.path.join(self.location,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
try:
myf = codecs.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
except (IOError, OSError) as e:
if errno.ENOENT == e.errno:
try:
self._ensure_dirs(cpv)
myf = codecs.open(_unicode_encode(fp,
encoding=_encodings['fs'], errors='strict'),
mode='w', encoding=_encodings['repo.content'],
errors='backslashreplace')
except (OSError, IOError) as e:
raise cache_errors.CacheCorruption(cpv, e)
else:
raise cache_errors.CacheCorruption(cpv, e)
try:
for k in self._write_keys:
v = values.get(k)
if not v:
continue
myf.write("%s=%s\n" % (k, v))
finally:
myf.close()
self._ensure_access(fp)
#update written. now we move it.
new_fp = os.path.join(self.location,cpv)
try:
os.rename(fp, new_fp)
except (OSError, IOError) as e:
os.remove(fp)
raise cache_errors.CacheCorruption(cpv, e)
开发者ID:Neuvoo,项目名称:legacy-portage,代码行数:40,代码来源:flat_hash.py
示例17: ionice
def ionice(settings):
ionice_cmd = settings.get("PORTAGE_IONICE_COMMAND")
if ionice_cmd:
ionice_cmd = portage.util.shlex_split(ionice_cmd)
if not ionice_cmd:
return
from portage.util import varexpand
variables = {"PID" : str(os.getpid())}
cmd = [varexpand(x, mydict=variables) for x in ionice_cmd]
try:
rval = portage.process.spawn(cmd, env=os.environ)
except portage.exception.CommandNotFound:
# The OS kernel probably doesn't support ionice,
# so return silently.
return
if rval != os.EX_OK:
out = portage.output.EOutput()
out.eerror("PORTAGE_IONICE_COMMAND returned %d" % (rval,))
out.eerror("See the make.conf(5) man page for PORTAGE_IONICE_COMMAND usage instructions.")
开发者ID:fastinetserver,项目名称:portage-idfetch,代码行数:23,代码来源:main.py
示例18: _start
def _start(self):
self.phase = "package"
self.tree = "porttree"
pkg = self.pkg
root_config = pkg.root_config
portdb = root_config.trees["porttree"].dbapi
bintree = root_config.trees["bintree"]
ebuild_path = portdb.findname(pkg.cpv)
if ebuild_path is None:
raise AssertionError("ebuild not found for '%s'" % pkg.cpv)
settings = self.settings
debug = settings.get("PORTAGE_DEBUG") == "1"
bintree.prevent_collision(pkg.cpv)
binpkg_tmpfile = os.path.join(bintree.pkgdir,
pkg.cpv + ".tbz2." + str(os.getpid()))
self._binpkg_tmpfile = binpkg_tmpfile
settings["PORTAGE_BINPKG_TMPFILE"] = binpkg_tmpfile
settings.backup_changes("PORTAGE_BINPKG_TMPFILE")
try:
EbuildProcess._start(self)
finally:
settings.pop("PORTAGE_BINPKG_TMPFILE", None)
开发者ID:TommyD,项目名称:gentoo-portage-multilib,代码行数:24,代码来源:EbuildBinpkg.py
示例19: hardlock_name
def hardlock_name(path):
base, tail = os.path.split(path)
return os.path.join(base, ".%s.hardlock-%s-%s" %
(tail, os.uname()[1], os.getpid()))
开发者ID:aeroniero33,项目名称:portage,代码行数:4,代码来源:locks.py
示例20: hardlock_name
def hardlock_name(path):
return path+".hardlock-"+os.uname()[1]+"-"+str(os.getpid())
开发者ID:TommyD,项目名称:gentoo-portage-multilib,代码行数:2,代码来源:locks.py
注:本文中的portage.os.getpid函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论