重新启动Python应用程序 [英] Restarting a Python Application

查看:82
本文介绍了重新启动Python应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我打包了一个我正在开发成可执行文件的应用程序。在应用程序的
中,它具有用户可配置的选项。我想要一种方式

来重启应用程序,以便用户选择的新选项可以应用
。 Firefox可以自行重启。有谁知道怎么用
用Python完成这个?


这是我试过的:


<代码>


exePath = os.path.join(os.getcwd(),''myprogram.exe'')

subprocess.Popen(exePath)

sys.exit()


< / code>


这不起作用。它关闭了程序,但另一个实例没有出现



提示将不胜感激。


Mike

解决方案

7月3日下午2:27,kyoso ... @ gmail.com写道:





我打包了一个我正在开发成可执行文件的应用程序。在应用程序的
中,它具有用户可配置的选项。我想要一种方式

来重启应用程序,以便用户选择的新选项可以应用
。 Firefox可以自行重启。有谁知道怎么用
用Python完成这个?


这是我试过的:


<代码>


exePath = os.path.join(os.getcwd(),''myprogram.exe'')

subprocess.Popen(exePath)

sys.exit()


< / code>


这不起作用。它关闭了程序,但另一个实例没有出现



提示将不胜感激。


Mike



您可以将程序打包成函数或类,只需重新启动即可。

展开 | 选择 | Wrap | 行号


7月3日下午5点,Matimus< mccre ... @ gmail.comwrote:


7月3日下午2:27,kyoso ... @ gmail.com写道:




我打包了一个我正在开发成可执行文件的应用程序。在应用程序的
中,它具有用户可配置的选项。我想要一种方式

来重启应用程序,以便用户选择的新选项可以应用
。 Firefox可以自行重启。有谁知道如何在Python中完成这个


以下是我的尝试:


< code>


exePath = os.path.join(os.getcwd(),''myprogram.exe'')

subprocess.Popen(exePath)

sys.exit()


< / code>


这不起作用。它关闭了程序,但另一个实例没有出现


提示将不胜感激。


Mike



您可以将程序打包成函数或类,只需

重新开始。

展开 | 选择 | Wrap | 行号


呃..这将是一个转贴OP,但我忘了点击回复

all再次。


这应该这样做:


os.execv(sys.argv [0],sys.argv)


不确定该声明的可移植性如何。

2007年7月3日, ky ****** @ gmail.com < ky ****** @ gmail.comwrote:





我打包了一个我正在开发成可执行文件的应用程序。在应用程序的
中,它具有用户可配置的选项。我想要一种方式

来重启应用程序,以便用户选择的新选项可以应用
。 Firefox可以自行重启。有谁知道怎么用
用Python完成这个?


这是我试过的:


<代码>


exePath = os.path.join(os.getcwd(),''myprogram.exe'')

subprocess.Popen(exePath)

sys.exit()


< / code>


这不起作用。它关闭了程序,但另一个实例没有出现



提示将不胜感激。


Mike


-
http://mail.python.org/mailman/listinfo/python-list



-

Kelvie


Hi,

I packaged up an application I am developing into an executable. In
the application, it has user configurable options. I would like a way
to restart the application so that the new options the user chooses
can be applied. Firefox can restart itself. Does anyone know how to
accomplish this in Python?

Here is what I tried:

<code>

exePath = os.path.join(os.getcwd(), ''myprogram.exe'')
subprocess.Popen(exePath)
sys.exit()

</code>

This didn''t work. It closed the program, but another instance did not
appear.

Tips would be appreciated.

Mike

解决方案

On Jul 3, 2:27 pm, kyoso...@gmail.com wrote:

Hi,

I packaged up an application I am developing into an executable. In
the application, it has user configurable options. I would like a way
to restart the application so that the new options the user chooses
can be applied. Firefox can restart itself. Does anyone know how to
accomplish this in Python?

Here is what I tried:

<code>

exePath = os.path.join(os.getcwd(), ''myprogram.exe'')
subprocess.Popen(exePath)
sys.exit()

</code>

This didn''t work. It closed the program, but another instance did not
appear.

Tips would be appreciated.

Mike

You could package your program into a function or class and just
restart that.

Expand|Select|Wrap|Line Numbers


On Jul 3, 5:00 pm, Matimus <mccre...@gmail.comwrote:

On Jul 3, 2:27 pm, kyoso...@gmail.com wrote:

Hi,

I packaged up an application I am developing into an executable. In
the application, it has user configurable options. I would like a way
to restart the application so that the new options the user chooses
can be applied. Firefox can restart itself. Does anyone know how to
accomplish this in Python?

Here is what I tried:

<code>

exePath = os.path.join(os.getcwd(), ''myprogram.exe'')
subprocess.Popen(exePath)
sys.exit()

</code>

This didn''t work. It closed the program, but another instance did not
appear.

Tips would be appreciated.

Mike


You could package your program into a function or class and just
restart that.

Expand|Select|Wrap|Line Numbers


Ugh.. this would be a repost for the OP, but I forgot to hit "reply to
all" again.

This should do it:

os.execv(sys.argv[0], sys.argv)

Not sure how portable that statement is, though.
On 7/3/07, ky******@gmail.com <ky******@gmail.comwrote:

Hi,

I packaged up an application I am developing into an executable. In
the application, it has user configurable options. I would like a way
to restart the application so that the new options the user chooses
can be applied. Firefox can restart itself. Does anyone know how to
accomplish this in Python?

Here is what I tried:

<code>

exePath = os.path.join(os.getcwd(), ''myprogram.exe'')
subprocess.Popen(exePath)
sys.exit()

</code>

This didn''t work. It closed the program, but another instance did not
appear.

Tips would be appreciated.

Mike

--
http://mail.python.org/mailman/listinfo/python-list


--
Kelvie


这篇关于重新启动Python应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆