本文整理汇总了Python中os.execvpe方法的典型用法代码示例。如果您正苦于以下问题:Python os.execvpe方法的具体用法?Python os.execvpe怎么用?Python os.execvpe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.execvpe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exec_fork
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def exec_fork(l, env):
pid = os.fork()
if not pid:
# Child process.
exitval = 127
try:
os.execvpe(l[0], l, env)
except OSError as e:
exitval = exitvalmap.get(e[0], e[0])
sys.stderr.write("scons: %s: %s\n" % (l[0], e[1]))
os._exit(exitval)
else:
# Parent process.
pid, stat = os.waitpid(pid, 0)
if stat & 0xff:
return stat | 0x80
return stat >> 8
示例2: _execChild
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def _execChild(self, path, uid, gid, executable, args, environment):
"""
The exec() which is done in the forked child.
"""
if path:
os.chdir(path)
if uid is not None or gid is not None:
if uid is None:
uid = os.geteuid()
if gid is None:
gid = os.getegid()
# set the UID before I actually exec the process
os.setuid(0)
os.setgid(0)
switchUID(uid, gid)
os.execvpe(executable, args, environment)
示例3: test_executionError
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def test_executionError(self):
"""
Raise an error during execvpe to check error management.
"""
cmd = self.getCommand('false')
d = defer.Deferred()
p = TrivialProcessProtocol(d)
def buggyexecvpe(command, args, environment):
raise RuntimeError("Ouch")
oldexecvpe = os.execvpe
os.execvpe = buggyexecvpe
try:
reactor.spawnProcess(p, cmd, [b'false'], env=None,
usePTY=self.usePTY)
def check(ignored):
errData = b"".join(p.errData + p.outData)
self.assertIn(b"Upon execvpe", errData)
self.assertIn(b"Ouch", errData)
d.addCallback(check)
finally:
os.execvpe = oldexecvpe
return d
示例4: reexec
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def reexec(self):
"""\
Relaunch the master and workers.
"""
if self.pidfile is not None:
self.pidfile.rename("%s.oldbin" % self.pidfile.fname)
self.reexec_pid = os.fork()
if self.reexec_pid != 0:
self.master_name = "Old Master"
return
environ = self.cfg.env_orig.copy()
fds = [l.fileno() for l in self.LISTENERS]
environ['GUNICORN_FD'] = ",".join([str(fd) for fd in fds])
os.chdir(self.START_CTX['cwd'])
self.cfg.pre_exec(self)
# exec the process using the original environnement
os.execvpe(self.START_CTX[0], self.START_CTX['args'], environ)
示例5: execute_new_nvim_process
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def execute_new_nvim_process(self, silent, nvr, options, arguments):
if not silent:
print(textwrap.dedent('''\
[*] Starting new nvim process using $NVR_CMD or 'nvim'.
Use --nostart to avoid starting a new process.
'''))
args = os.environ.get('NVR_CMD')
args = args.split(' ') if args else ['nvim']
multiprocessing.Process(target=self.try_attach, args=(args, nvr, options, arguments)).start()
os.environ['NVIM_LISTEN_ADDRESS'] = self.address
try:
os.execvpe(args[0], args, os.environ)
except FileNotFoundError:
print("[!] Can't start new nvim process: '{}' is not in $PATH.".format(args[0]))
sys.exit(1)
示例6: spawn
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def spawn(self):
env = self.env
env['TERM'] = 'linux'
self.pid, self.master = pty.fork()
if self.pid == 0:
if callable(self.command):
try:
try:
self.command()
except:
sys.stderr.write(traceback.format_exc())
sys.stderr.flush()
finally:
os._exit(0)
else:
os.execvpe(self.command[0], self.command, env)
if self.main_loop is None:
fcntl.fcntl(self.master, fcntl.F_SETFL, os.O_NONBLOCK)
atexit.register(self.terminate)
示例7: test_executionError
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def test_executionError(self):
"""
Raise an error during execvpe to check error management.
"""
cmd = self.getCommand('false')
d = defer.Deferred()
p = TrivialProcessProtocol(d)
def buggyexecvpe(command, args, environment):
raise RuntimeError("Ouch")
oldexecvpe = os.execvpe
os.execvpe = buggyexecvpe
try:
reactor.spawnProcess(p, cmd, ['false'], env=None,
usePTY=self.usePTY)
def check(ignored):
errData = "".join(p.errData + p.outData)
self.assertIn("Upon execvpe", errData)
self.assertIn("Ouch", errData)
d.addCallback(check)
finally:
os.execvpe = oldexecvpe
return d
示例8: _run
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def _run(*, port: str, db: Optional[Path]=None, timezone: str, quiet: bool):
logger = get_logger()
env = {
**os.environ,
# not sure if there is a simpler way to communicate with hug..
# # TODO here
_ENV_CONFIG: json.dumps({
'timezone': timezone,
**({} if db is None else {'db': str(db)})
}),
}
args = [
'python3',
'-m', 'hug', # TODO eh, not sure about this. what if user had it already installed?? it's a mess..
*(['--silent'] if quiet else []),
'-p', port,
'-f', __file__,
]
logger.info('Running server: %s', args)
os.execvpe('python3', args, env)
示例9: _execute
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def _execute(path, argv, environ):
if environ is None:
os.execvp(path, argv)
else:
os.execvpe(path, argv, environ)
return
# endregion
示例10: exec_cc
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def exec_cc(cmd, args):
"""
Execute with current context.
Yes, you're right -- I'm naming it after call/cc.
Return a generator.
The first yielded one is the status of
the execution of subprocess command.
The following ones are the the buffer batches of stderr,
each of which is a Python 'bytes' object
"""
file = cmd
err_in, err_out = os.pipe()
out_in, out_out = os.pipe()
if os.fork():
_, status = os.wait()
os.close(err_out)
os.close(out_out)
yield status
while True:
load = os.read(err_in, 1024)
if not load:
break
yield load
else:
# for child process
os.close(err_in)
os.close(out_in)
os.dup2(err_out, sys.stderr.fileno())
os.dup2(out_out, sys.stdout.fileno())
os.execvpe(file, [cmd, *args], dict(os.environ))
# in case that os.execvp fails
sys.exit(127)
示例11: reexec
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def reexec(self):
"""\
Relaunch the master and workers.
"""
if self.reexec_pid != 0:
self.log.warning("USR2 signal ignored. Child exists.")
return
if self.master_pid != 0:
self.log.warning("USR2 signal ignored. Parent exists")
return
master_pid = os.getpid()
self.reexec_pid = os.fork()
if self.reexec_pid != 0:
return
self.cfg.pre_exec(self)
environ = self.cfg.env_orig.copy()
fds = [l.fileno() for l in self.LISTENERS]
environ['GUNICORN_FD'] = ",".join([str(fd) for fd in fds])
environ['GUNICORN_PID'] = str(master_pid)
os.chdir(self.START_CTX['cwd'])
# exec the process using the original environnement
os.execvpe(self.START_CTX[0], self.START_CTX['args'], environ)
示例12: execute
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def execute(self, bin, *args, **kwargs):
bin = self._bin(bin)
if not self._is_windows:
args = [bin] + list(args)
if "env" in kwargs:
return os.execvpe(bin, args, kwargs["env"])
else:
return os.execvp(bin, args)
else:
exe = subprocess.Popen([bin] + list(args), **kwargs)
exe.communicate()
return exe.returncode
示例13: test_execvpe_with_bad_arglist
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def test_execvpe_with_bad_arglist(self):
self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
示例14: _spawn_posix
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
log.info(' '.join(cmd))
if dry_run:
return
exec_fn = search_path and os.execvp or os.execv
exec_args = [cmd[0], cmd]
if sys.platform == 'darwin':
global _cfg_target, _cfg_target_split
if _cfg_target is None:
_cfg_target = sysconfig.get_config_var(
'MACOSX_DEPLOYMENT_TARGET') or ''
if _cfg_target:
_cfg_target_split = [int(x) for x in _cfg_target.split('.')]
if _cfg_target:
# ensure that the deployment target of build process is not less
# than that used when the interpreter was built. This ensures
# extension modules are built with correct compatibility values
cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
if _cfg_target_split > [int(x) for x in cur_target.split('.')]:
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
'now "%s" but "%s" during configure'
% (cur_target, _cfg_target))
raise DistutilsPlatformError(my_msg)
env = dict(os.environ,
MACOSX_DEPLOYMENT_TARGET=cur_target)
exec_fn = search_path and os.execvpe or os.execve
exec_args.append(env)
pid = os.fork()
if pid == 0: # in the child
try:
exec_fn(*exec_args)
except OSError, e:
sys.stderr.write("unable to execute %s: %s\n" %
(cmd[0], e.strerror))
os._exit(1)
sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
os._exit(1)
示例15: create_execve
# 需要导入模块: import os [as 别名]
# 或者: from os import execvpe [as 别名]
def create_execve(original_name):
"""
os.execve(path, args, env)
os.execvpe(file, args, env)
"""
def new_execve(path, args, env):
if _get_apply_arg_patching():
args = patch_args(args, is_exec=True)
send_process_created_message()
return getattr(os, original_name)(path, args, env)
return new_execve