当前位置: 首页>>代码示例>>Python>>正文


Python os.execv方法代码示例

本文整理汇总了Python中os.execv方法的典型用法代码示例。如果您正苦于以下问题:Python os.execv方法的具体用法?Python os.execv怎么用?Python os.execv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.execv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _set_cloexec

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def _set_cloexec(self):
        """Set the CLOEXEC flag on all open files (except stdin/out/err).

        If self.max_cloexec_files is an integer (the default), then on
        platforms which support it, it represents the max open files setting
        for the operating system. This function will be called just before
        the process is restarted via os.execv() to prevent open files
        from persisting into the new process.

        Set self.max_cloexec_files to 0 to disable this behavior.
        """
        for fd in range(3, self.max_cloexec_files):  # skip stdin/out/err
            try:
                flags = fcntl.fcntl(fd, fcntl.F_GETFD)
            except IOError:
                continue
            fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:19,代码来源:wspbus.py

示例2: hash_check

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def hash_check(self, pb2_file_name, pb2_grpc_file_name):
        # If the protobufs have changed, then it's likely that new models
        # have been downloaded. One way we have dealt with this in the past
        # is to force a reload() of the affected modules. However, it seems
        # safer to force a full synchronizer restart as this will allow
        # the synchronizer to perform a version check against the core, and
        # it will refresh any data structures that might be affected by the
        # new models.

        pb2_hash = hashlib.sha256(open(pb2_file_name).read())
        pb2_grpc_hash = hashlib.sha256(open(pb2_grpc_file_name).read())

        if (pb2_file_name in self.hashes) or (pb2_grpc_file_name in self.hashes):
            if (pb2_hash != self.hashes[pb2_file_name]) or (pb2_grpc_hash != self.hashes[pb2_grpc_file_name]):
                log.warning(
                    "Protobuf change detected, restarting the synchronzier"
                )
                os.execv(sys.executable, ["python"] + sys.argv)

        self.hashes[pb2_file_name] = pb2_hash
        self.hashes[pb2_grpc_file_name] = pb2_grpc_hash 
开发者ID:open-cloud,项目名称:xos,代码行数:23,代码来源:xos_grpc_client.py

示例3: shutdown

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def shutdown():
    if lp_events.timer != None:
        lp_events.timer.cancel()
    scripts.to_run = []
    for x in range(9):
        for y in range(9):
            if scripts.threads[x][y] != None:
                scripts.threads[x][y].kill.set()
    if window.lp_connected:
        scripts.unbind_all()
        lp_events.timer.cancel()
        launchpad_connector.disconnect(lp)
        window.lp_connected = False
    logger.stop()
    if window.restart:
        if IS_EXE:
            os.startfile(sys.argv[0])
        else:
            os.execv(sys.executable, ["\"" + sys.executable + "\""] + sys.argv)
    sys.exit("[LPHK] Shutting down...") 
开发者ID:nimaid,项目名称:LPHK,代码行数:22,代码来源:LPHK.py

示例4: main

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def main():
    config_path = os.environ.get('iris-relay_CFG_PATH', '/home/iris-relay/config/config.yaml')
    with open(config_path, 'r') as config_file:
        iris_relay_config = yaml.safe_load(config_file)
    mysql_config = iris_relay_config['db']['conn']['kwargs']

    # It often takes several seconds for MySQL to start up. iris-relay dies upon start
    # if it can't immediately connect to MySQL, so we have to wait for it.
    wait_for_mysql(mysql_config)

    if 'DOCKER_DB_BOOTSTRAP' in os.environ:
        if not os.path.exists(initializedfile):
            initialize_mysql_schema(mysql_config)

    os.execv('/usr/bin/uwsgi',
             ['', '--yaml', '/home/iris-relay/daemons/uwsgi.yaml:prod']) 
开发者ID:linkedin,项目名称:iris-relay,代码行数:18,代码来源:entrypoint.py

示例5: _spawn_posix

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [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
    pid = os.fork()

    if pid == 0:  # in the child
        try:
            exec_fn(cmd[0], cmd)
        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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:19,代码来源:spawn.py

示例6: GClector

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def GClector(self):
        print('GC is invoked, %d calls in map' % len(self.ccmap))
        if self.debug_mode:
            print(self.global_config['_sip_tm'].tclient, self.global_config['_sip_tm'].tserver)
            for cc in tuple(self.ccmap):
                try:
                    print(cc.uaA.state, cc.uaO.state)
                except AttributeError:
                    print(None)
        else:
            print('[%d]: %d client, %d server transactions in memory' % \
              (os.getpid(), len(self.global_config['_sip_tm'].tclient), len(self.global_config['_sip_tm'].tserver)))
        if self.safe_restart:
            if len(self.ccmap) == 0:
                self.global_config['_sip_tm'].userv.close()
                os.chdir(self.global_config['_orig_cwd'])
                argv = [sys.executable,]
                argv.extend(self.global_config['_orig_argv'])
                os.execv(sys.executable, argv)
                # Should not reach this point!
            self.el.ival = 1
        #print gc.collect()
        if len(gc.garbage) > 0:
            print(gc.garbage) 
开发者ID:sippy,项目名称:b2bua,代码行数:26,代码来源:b2bua_radius.py

示例7: keep_trying

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def keep_trying(client, reactor):
    # Keep checking the connection to wait for it to become unavailable.
    # Then reconnect. The strategy is to send NoOp operations, one per second, until eventually a NoOp throws an
    # exception. This will indicate the server has reset. When that happens, we force the client to reconnect, and
    # it will download a new API from the server.

    from xosapi.xos_grpc_client import Empty

    try:
        client.utility.NoOp(Empty())
    except Exception as e:
        # If we caught an exception, then the API has become unavailable.
        # So reconnect.

        log.exception("exception in NoOp", e=e)
        log.info("restarting synchronizer")

        os.execv(sys.executable, ["python"] + sys.argv)
        return

    reactor.callLater(1, functools.partial(keep_trying, client, reactor)) 
开发者ID:open-cloud,项目名称:xos,代码行数:23,代码来源:modelaccessor.py

示例8: reExec

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def reExec(self):
        """
        Removes pidfile, registers an exec to happen after shutdown, then
        stops the reactor.
        """
        self.log.warn("SIGHUP received - restarting")
        try:
            self.log.info("Removing pidfile: {log_source.pidfilePath}")
            os.remove(self.pidfilePath)
        except OSError:
            pass
        self.reactor.addSystemEventTrigger(
            "after", "shutdown", os.execv,
            sys.executable, [sys.executable] + sys.argv
        )
        self.reactor.stop() 
开发者ID:apple,项目名称:ccs-twistedextensions,代码行数:18,代码来源:service.py

示例9: run

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def run(cmd, close_in_child, keep_in_child, with_pgrp=True):
	child = os.fork()
	if child:
		return child
	if with_pgrp:
		os.setpgrp() # this pgrp is killed if the job fails
	for fd in close_in_child:
		os.close(fd)
	keep_in_child = set(keep_in_child)
	keep_in_child.add(int(os.getenv('BD_STATUS_FD')))
	keep_in_child.add(int(os.getenv('BD_TERM_FD')))
	close_fds(keep_in_child)
	# unreadable stdin - less risk of stuck jobs
	devnull = os.open('/dev/null', os.O_RDONLY)
	os.dup2(devnull, 0)
	os.close(devnull)
	if PY3:
		keep_in_child.update([1, 2])
		for fd in keep_in_child:
			os.set_inheritable(fd, True)
	os.execv(cmd[0], cmd)
	os._exit() 
开发者ID:eBay,项目名称:accelerator,代码行数:24,代码来源:dispatch.py

示例10: bootstrap

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def bootstrap(self, f, *a, **kw):
        import marshal
        import cPickle as pickle

        pipe_r, pipe_w = os.pipe()
        os.write(pipe_w, pickle.dumps((marshal.dumps(f.func_code), a, kw)))
        os.close(pipe_w)

        bootstrap = '\n'.join(x.strip() for x in ("""
            import cPickle as pickle
            import marshal
            import types
            import sys
            import os

            code, a, kw = pickle.loads(os.read(%(pipe_r)s, 4096))
            os.close(%(pipe_r)s)

            f = types.FunctionType(marshal.loads(code), globals(), 'f')
            f(*a, **kw)
        """ % {'pipe_r': pipe_r}).split('\n') if x)

        argv = [sys.executable, '-u', '-c', bootstrap]
        os.execv(argv[0], argv) 
开发者ID:cablehead,项目名称:vanilla,代码行数:26,代码来源:process.py

示例11: open

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def open(self, loop):
        pid, self.fd = os.forkpty()
        if pid == 0:
            if bot.settings.get("user") and "login" in bot.settings.get("user") and bot.settings.get("user")["login"]:
                    os.execv(bot.settings.get("terminal")["su_path"],
                             [bot.settings.get("terminal")["su_path"], "-", bot.settings.get("user")["login"], "-s", bot.settings.get("terminal")["shell_path"]])
            else:
                os.execv(bot.settings.get("terminal")["shell_path"], [bot.settings.get("terminal")["shell_path"], ])

            sys.exit(0)
        else:
            self.status = "working"

            pty_output = threading.Thread(target=self.watch_output)
            pty_output.start()

            self.update_output(loop)

        return self 
开发者ID:Adikso,项目名称:BashBot,代码行数:21,代码来源:bash.py

示例12: restart

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def restart(self):
        """Restart the process (may close connections).

        This method does not restart the process from the calling thread;
        instead, it stops the bus and asks the main thread to call execv.
        """
        self.execv = True
        self.exit() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:10,代码来源:wspbus.py

示例13: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def __init__(self):
        """Initialize pub/sub bus."""
        self.execv = False
        self.state = states.STOPPED
        channels = 'start', 'stop', 'exit', 'graceful', 'log', 'main'
        self.listeners = dict(
            (channel, set())
            for channel in channels
        )
        self._priorities = {} 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:12,代码来源:wspbus.py

示例14: _do_execv

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def _do_execv(self):
        """Re-execute the current process.

        This must be called from the main thread, because certain platforms
        (OS X) don't allow execv to be called in a child thread very well.
        """
        try:
            args = self._get_true_argv()
        except NotImplementedError:
            """It's probably win32 or GAE"""
            args = [sys.executable] + self._get_interpreter_argv() + sys.argv

        self.log('Re-spawning %s' % ' '.join(args))

        self._extend_pythonpath(os.environ)

        if sys.platform[:4] == 'java':
            from _systemrestart import SystemRestart
            raise SystemRestart
        else:
            if sys.platform == 'win32':
                args = ['"%s"' % arg for arg in args]

            os.chdir(_startup_cwd)
            if self.max_cloexec_files:
                self._set_cloexec()
            os.execv(sys.executable, args) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:29,代码来源:wspbus.py

示例15: start_nginx

# 需要导入模块: import os [as 别名]
# 或者: from os import execv [as 别名]
def start_nginx(nginx, nginx_conf):
    try:
        # Control is relinquished to nginx process after this line
        os.execv(nginx, ['nginx', '-p', '/usr', '-c', nginx_conf])
    except OSError as err:
        logging.error("Failed to launch NGINX: " + nginx)
        logging.error(err.strerror)
        sys.exit(3) 
开发者ID:cloudendpoints,项目名称:endpoints-tools,代码行数:10,代码来源:start_esp.py


注:本文中的os.execv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。