本文整理汇总了Python中os.execlp方法的典型用法代码示例。如果您正苦于以下问题:Python os.execlp方法的具体用法?Python os.execlp怎么用?Python os.execlp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.execlp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: spawn
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def spawn(argv, master_read=_read, stdin_read=_read):
"""Create a spawned process."""
if type(argv) == type(''):
argv = (argv,)
pid, master_fd = fork()
if pid == CHILD:
os.execlp(argv[0], *argv)
try:
mode = tty.tcgetattr(STDIN_FILENO)
tty.setraw(STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
try:
_copy(master_fd, master_read, stdin_read)
except (IOError, OSError):
if restore:
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(master_fd)
示例2: run
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def run(command):
child_pid = os.fork()
if child_pid == 0:
os.execlp(command[0], *command)
else:
while True:
try:
os.waitpid(child_pid, 0)
except OSError as error:
if error.errno == errno.ECHILD:
# No child processes.
# It has exited already.
break
elif error.errno == errno.EINTR:
# Interrupted system call.
# This happens when resizing the terminal.
pass
else:
# An actual error occurred.
raise
示例3: create_execl
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def create_execl(original_name):
def new_execl(path, *args):
"""
os.execl(path, arg0, arg1, ...)
os.execle(path, arg0, arg1, ..., env)
os.execlp(file, arg0, arg1, ...)
os.execlpe(file, arg0, arg1, ..., env)
"""
if _get_apply_arg_patching():
args = patch_args(args, is_exec=True)
send_process_created_message()
return getattr(os, original_name)(path, *args)
return new_execl
示例4: _parse
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def _parse(self, parser):
options, args = parser.parse_args()
if not options.allow_root and self._is_root():
parser.error(
"running as root - " +
"run as a different user or specify the --allow-root " +
"command line option")
if options.python is not None:
os.execlp(options.python, options.python, sys.argv[0], *args)
if sys.version_info < (2, 6):
version = platform.python_version()
parser.error(
"this tool requires python >= 2.6 " +
"(you are running python " + version + "), " +
"use the option -p/--python to define a suitable python " +
"executable")
return options, args
示例5: __call__
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def __call__(self, *objs):
if self._fo is None:
masterfd, slavefd = os.openpty()
pid = os.fork()
if pid: # parent
os.close(masterfd)
self._fo = os.fdopen(slavefd, "w+b", 0)
if self._do_stderr:
os.close(2)
os.dup2(slavefd, 2)
else: # child
os.close(slavefd)
os.execlp("urxvt", "urxvt", "-pty-fd", str(masterfd))
fo = self._fo
fo.write("{}: ".format(datetime.now()).encode("utf-8"))
lo = len(objs) - 1
for i, o in enumerate(objs):
fo.write(repr(o).encode("utf-8"))
if i < lo:
fo.write(b", ")
fo.write(b"\n")
# automatic, lazy construction of DEBUG object
示例6: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def __init__(self):
masterfd, slavefd = os.openpty()
pid = os.fork()
if pid: # parent
os.close(masterfd)
self._fo = os.fdopen(slavefd, "w+", 0)
else: # child
os.close(slavefd)
os.execlp("urxvt", "urxvt", "-pty-fd", str(masterfd))
self.mode = "rw"
self.closed = 0
self.softspace = 0
# reading methods
self.read = self._fo.read
self.readline = self._fo.readline
self.readlines = self._fo.readlines
# writing methods
self.write = self._fo.write
self.flush = self._fo.flush
self.writelines = self._fo.writelines
示例7: spawn
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def spawn(argv, master_read=_read, stdin_read=_read):
"""Create a spawned process."""
if type(argv) == type(''):
argv = (argv,)
pid, master_fd = fork()
if pid == CHILD:
os.execlp(argv[0], *argv)
try:
mode = tty.tcgetattr(STDIN_FILENO)
tty.setraw(STDIN_FILENO)
restore = 1
except tty.error: # This is the same as termios.error
restore = 0
try:
_copy(master_fd, master_read, stdin_read)
except OSError:
if restore:
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(master_fd)
return os.waitpid(pid, 0)[1]
示例8: main
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def main(argv=None):
args = parse_paasta_api_args()
if args.debug:
os.environ["PAASTA_API_DEBUG"] = "1"
if args.soa_dir:
os.environ["PAASTA_API_SOA_DIR"] = args.soa_dir
if args.cluster:
os.environ["PAASTA_API_CLUSTER"] = args.cluster
os.execlp(
os.path.join(sys.exec_prefix, "bin", "gunicorn"),
"gunicorn",
"-w",
"4",
"--bind",
f":{args.port}",
"paasta_tools.api.api:application",
)
示例9: xserver_start
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def xserver_start(display, executable='Xvfb', authfile=None):
pid = os.fork()
if pid != 0:
return pid
if authfile is None:
authfile = os.devnull
# This will make the xserver send us a SIGUSR1 when ready.
signal.signal(signal.SIGUSR1, signal.SIG_IGN)
cmd = [
executable,
'-auth', authfile,
'-noreset',
display,
]
print('starting xserver: `{0}`'.format(' '.join(cmd)))
os.execlp(cmd[0], *cmd)
示例10: default_bottom_halves_after_sync
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def default_bottom_halves_after_sync(self, *args, **kwargs):
if self.func is None:
if not self.nscmd:
self.nscmd = [find_shell()]
elif not isinstance(self.nscmd, list):
self.nscmd = [self.nscmd]
if "pid" not in self.namespaces:
args = self.nscmd
elif self.init_prog is not None:
args = [self.init_prog] + self.nscmd
else:
args = [sys.executable, self.my_init, "--skip-startup-files",
"--skip-runit", "--quiet"] + self.nscmd
os.execlp(args[0], *args)
else:
if hasattr(self.func, '__call__'):
self.func(*args, **kwargs)
else:
raise NamespaceSettingError()
示例11: psql
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def psql(host, app_name):
r = requests.get('%s/api/apps/%s/databases' % (host, quote(app_name.encode('utf-8'))), headers = {
'Content-Type': 'application/json',
})
if r.status_code != 200:
if r.status_code == 401:
raise auth.AuthException()
raise Exception(r.text)
else:
data = json.loads(r.text)["data"]
urls = list(filter(lambda d: d["state"] == "AVAILABLE", data))
if len(urls) > 1:
# TODO: allow user to specify database
click.echo("Found more than one database, using: %s" % urls[0]["id"])
elif len(urls) < 1:
click.echo("Sorry, no databases found.")
else:
url = urls[0]["url"]
try:
os.execlp("psql", "psql", url)
except OSError as e:
if e.errno == errno.ENOENT:
raise Exception("Sorry, we could not find psql. Try installing it and try again.")
else:
raise
示例12: run
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def run(options):
try:
radl = ClusterStore.load(options.clustername)
front_system = radl.get(system("front"))
ssh_port = get_out_port(radl, 22)
if front_system.getValue("disk.0.os.credentials.private_key"):
ops = CmdSsh._connect_key(front_system, ssh_port)
else:
ops = CmdSsh._connect_password(front_system, ssh_port)
if options.sshcommand:
ops.extend(options.sshcommand)
if options.show_only:
CLI.display(" ".join(ops))
sys.exit(0)
os.execlp(ops[0], *ops)
except OSError as e:
CLI.display("Error connecting to cluster '%s': %s\n"
"Probably 'sshpass' or 'ssh' program is not installed!" % (options.clustername, str(e)),
level=logging.ERROR)
sys.exit(1)
except Exception as e:
CLI.display("Error connecting to cluster '%s': %s" % (options.clustername, str(e)),
level=logging.ERROR)
sys.exit(1)
示例13: check_sudo
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def check_sudo():
if os.geteuid():
args = [sys.executable] + sys.argv
os.execlp('sudo', 'sudo', *args)
示例14: patch_new_process_functions_with_warning
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def patch_new_process_functions_with_warning():
monkey_patch_os('execl', create_warn_multiproc)
monkey_patch_os('execle', create_warn_multiproc)
monkey_patch_os('execlp', create_warn_multiproc)
monkey_patch_os('execlpe', create_warn_multiproc)
monkey_patch_os('execv', create_warn_multiproc)
monkey_patch_os('execve', create_warn_multiproc)
monkey_patch_os('execvp', create_warn_multiproc)
monkey_patch_os('execvpe', create_warn_multiproc)
monkey_patch_os('spawnl', create_warn_multiproc)
monkey_patch_os('spawnle', create_warn_multiproc)
monkey_patch_os('spawnlp', create_warn_multiproc)
monkey_patch_os('spawnlpe', create_warn_multiproc)
monkey_patch_os('spawnv', create_warn_multiproc)
monkey_patch_os('spawnve', create_warn_multiproc)
monkey_patch_os('spawnvp', create_warn_multiproc)
monkey_patch_os('spawnvpe', create_warn_multiproc)
monkey_patch_os('posix_spawn', create_warn_multiproc)
if not IS_JYTHON:
if not IS_WINDOWS:
monkey_patch_os('fork', create_warn_multiproc)
try:
import _posixsubprocess
monkey_patch_module(_posixsubprocess, 'fork_exec', create_warn_fork_exec)
except ImportError:
pass
else:
# Windows
try:
import _subprocess
except ImportError:
import _winapi as _subprocess
monkey_patch_module(_subprocess, 'CreateProcess', create_CreateProcessWarnMultiproc)
示例15: upload_zmodem
# 需要导入模块: import os [as 别名]
# 或者: from os import execlp [as 别名]
def upload_zmodem(self, filename):
"""Call external ZMODEM program to upload a file.
Return an ExitStatus object that should indicate success or failure.
"""
sockfd = self.sock.fileno()
pread, pwrite = os.pipe()
pid = os.fork()
if pid == 0: # child
os.dup2(sockfd, 0)
os.dup2(sockfd, 1)
os.dup2(pwrite, 2)
os.close(pread)
os.close(pwrite)
for fd in xrange(3,64):
try:
os.close(fd)
except:
pass
os.write(0, "rz -e -q -s +30\r") # needed with -e flag on sz
os.execlp("sz", "sz", "-e", "-q", "-y", "-L", "128", filename)
os._exit(1) # not normally reached
# parent
os.close(pwrite)
while True:
wpid, es = os.waitpid(pid, 0)
if wpid == pid:
break
errout = os.read(pread, 4096)
es = ExitStatus("sz {}".format(filename), es)
es.output = errout
return es