def restart(self, *extra_args):
python = sys.executable
args = [sys.argv[0]]
for arg in extra_args:
args.append(str(arg))
os.execl(python, python, *args)
python类execl()的实例源码
def restart(prefix, chan, params):
bot.do('QUIT', ' '.join(params))
bot.oqueue.join()
os.execl(sys.executable, sys.executable, * sys.argv)
def restart_program():
"""Restarts the current program.
Note: this function does not return. Any cleanup action (like
saving data) must be done before calling this function."""
python = sys.executable
os.execl(python, python, * sys.argv)
def restart_program():
"""Restarts the current program.
Note: this function does not return. Any cleanup action (like
saving data) must be done before calling this function."""
python = sys.executable
os.execl(python, python, * sys.argv)
def restart(self, ctx):
"""Restart the bot. Bot owner only."""
message = "Bot is going for restart NOW!"
logger.warning(message)
await ctx.send(message)
await ctx.bot.logout()
os.execl(sys.executable, sys.executable, *sys.argv)
def restart(bot, update):
bot.sendMessage(update.message.chat_id, "Bot is restarting...")
sleep(0.2)
os.execl(sys.executable, sys.executable, *sys.argv)
#@restricted
def main():
if hasattr(Qt, 'AA_EnableHighDpiScaling'):
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
if hasattr(Qt, 'AA_Use96Dpi'):
QCoreApplication.setAttribute(Qt.AA_Use96Dpi, True)
if hasattr(Qt, 'AA_ShareOpenGLContexts'):
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts, True)
if sys.platform == 'darwin':
QApplication.setStyle('Fusion')
atexit.register(MainWindow.cleanup)
app = SingleApplication(vidcutter.__appid__, sys.argv)
app.setApplicationName(vidcutter.__appname__)
app.setApplicationVersion(vidcutter.__version__)
app.setOrganizationDomain(vidcutter.__domain__)
app.setQuitOnLastWindowClosed(True)
win = MainWindow()
app.setActivationWindow(win)
app.messageReceived.connect(win.file_opener)
exit_code = app.exec_()
if exit_code == MainWindow.EXIT_CODE_REBOOT:
if sys.platform == 'win32':
if hasattr(win.cutter, 'mpvWidget'):
win.close()
QProcess.startDetached('"{}"'.format(qApp.applicationFilePath()))
else:
os.execl(sys.executable, sys.executable, *sys.argv)
sys.exit(exit_code)
def reboot():
import os
import sys
python = sys.executable
os.execl(python, python, * sys.argv)
def reboot(slackMessage):
####Reboot Mal.
import os
import sys
python = sys.executable
os.execl(python, python, * sys.argv)
def restart(self):
atexit.register(
os.execl, sys.executable,
sys.executable, *sys.argv)
self.loop.stop()
def restart(self, ctx):
"""Restarts this bot.
Usage: restart"""
echeck_perms(ctx, ('bot_owner',))
self.bot.store_writer.cancel()
await self.bot.store.commit()
if ctx.invoked_with != 'update':
await ctx.send('I\'ll try to restart. Hopefully I come back alive :stuck_out_tongue:')
self.logger.info('The bot is now restarting!')
# self.bot.is_restart = True
os.execl(sys.executable, sys.executable, *sys.argv)
def key_handler(key):
if key in ('q', 'Q', 'esc'):
raise urwid.ExitMainLoop()
elif key == 'ctrl r':
python = sys.executable
os.execl(python, python, *sys.argv)
def restart(self, ctx):
"""Restarts bot."""
try:
p = psutil.Process(os.getpid())
for handler in p.get_open_files() + p.connections():
os.close(handler.fd)
except Exception as e:
pass
python = sys.executable
os.execl(python, python, *sys.argv)
def StartUp():
debug("Startup")
if os.path.exists(SCRIPTHOME):
os.chdir(SCRIPTHOME)
oscmd = "git pull -f"
debug(oscmd)
os.system(oscmd)
botname = "stallmanbot.py"
debug(oscmd)
# For debugging outside of the Raspberry Pi
# oscmd = "diff -q %s %s/homemadescripts/%s" % (botname, HOME, botname)
# Original Raspberry Pi command
oscmd = "diff -q %s %s/bin/%s" % (botname, HOME, botname)
res = os.system(oscmd)
if res:
# new version detected
res = os.system("%s %s check" % (sys.executable, sys.argv[0]))
if res != 0:
debug("Versão bugada")
sys.exit(os.EX_OSERR)
debug("Updating bot...")
shutil.copy(botname, "%s/bin/%s" % (HOME, botname))
debug("Bot version updated.")
# check first
debug("Calling restart")
python = sys.executable
os.execl(python, python, *sys.argv)
# Update the foodporn.json file
run_foodporn_update()
def Reload(cmd):
debug(cmd.text)
if not cmd.from_user.username == botadm:
bot.reply_to(cmd, "Só patrão pode isso.")
return
try:
debug(cmd)
bot.reply_to(cmd, "Reloading...")
if os.path.exists(SCRIPTHOME):
os.chdir(SCRIPTHOME)
oscmd = "git pull -f"
debug(oscmd)
os.system(oscmd)
botname = "stallmanbot.py"
debug(oscmd)
oscmd = "diff -q %s %s/bin/%s" % (botname, HOME, botname)
res = os.system(oscmd)
if res:
# new version detected
res = os.system("%s %s" % (sys.executable, sys.argv[0]))
if res != 0:
debug("Versão bugada")
bot.send_message(cmd.chat.id, "Python crashed. Vou carregar saporra não. Vai que...")
return
debug("Updating bot...")
shutil.copy(botname, "%s/bin/%s" % (HOME, botname))
bot.send_message(cmd.chat.id, "Bot version updated.")
# check first
python = sys.executable
os.execl(python, python, *sys.argv)
except Exception as e:
try:
bot.reply_to(cmd, u"Deu merda... %s" % e)
except Exception as z:
print u"%s" % z
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)
"""
import os
args = patch_args(args)
send_process_created_message()
return getattr(os, original_name)(path, *args)
return new_execl
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)
if sys.platform != 'win32':
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)
def openstack_upgrade():
"""Perform action-managed OpenStack upgrade.
Upgrades packages to the configured openstack-origin version and sets
the corresponding action status as a result.
If the charm was installed from source we cannot upgrade it.
For backwards compatibility a config flag (action-managed-upgrade) must
be set for this code to run, otherwise a full service level upgrade will
fire on config-changed."""
if (do_action_openstack_upgrade('keystone',
do_openstack_upgrade,
register_configs())):
os.execl('./hooks/config-changed-postupgrade', '')
def do_openstack_upgrade_reexec(configs):
do_openstack_upgrade(configs)
log("Re-execing hook to pickup upgraded packages", level=INFO)
os.execl('./hooks/config-changed-postupgrade', '')
def do_openstack_upgrade_reexec(configs):
do_openstack_upgrade(configs)
log("Re-execing hook to pickup upgraded packages", level=INFO)
os.execl('./hooks/config-changed-postupgrade', '')