473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Restarting a Python Application

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

Jul 3 '07 #1
10 2134
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
  1. # global flag for restart.
  2. do_restart = False
  3.  
  4. def main(args=None):
  5. # program code
  6. # set do_restart and return to restart
  7.  
  8. if __name__ == "__main__":
  9. retval = main()
  10. while do_restart:
  11. retval = main()
  12. sys.exit(retval)
  13.  
  14.  
Jul 3 '07 #2
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
  1. # global flag for restart.
  2. do_restart = False
  3. def main(args=None):
  4.     # program code
  5.     # set do_restart and return to restart
  6. if __name__ == "__main__":
  7.     retval = main()
  8.     while do_restart:
  9.         retval = main()
  10.     sys.exit(retval)
  11.  
Actually I am using wxPython for a GUI front-end. Thus, it is already
in a class. I am not sure how to apply your idea to a program that is
already running in an infinite event loop.

Mike

Jul 6 '07 #3
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
Jul 7 '07 #4
On 7/7/07, Kelvie Wong <ke****@ieee.orgwrote:
Ugh.. this would be a repost for the OP, but I forgot to hit "reply to
all" again.
<rant>
Imagine if you wrote applications where the default behavior did not
do what was needed 99% of the time: how long do you think you'd be in
business?

The default behavior of replying to the original sender instead of the
list makes no sense. I've read the purist arguments against replying
to the list, but I subscribed to a *list*, not an individual sender.

I know that this post is pointless, since the people who run this list
seem to care more about abstract and misdirected notions of purity
than making things as useful and intelligent as possible, but after
seeing dozens of "please keep your reply on list" responses recently,
I had to vent.
</rant>
--

# p.d.
Jul 7 '07 #5
Peter Decker wrote:
On 7/7/07, Kelvie Wong <ke****@ieee.orgwrote:
>Ugh.. this would be a repost for the OP, but I forgot to hit "reply to
all" again.

<rant>
Imagine if you wrote applications where the default behavior did not
do what was needed 99% of the time: how long do you think you'd be in
business?

The default behavior of replying to the original sender instead of the
list makes no sense. I've read the purist arguments against replying
to the list, but I subscribed to a *list*, not an individual sender.

I know that this post is pointless, since the people who run this list
seem to care more about abstract and misdirected notions of purity
than making things as useful and intelligent as possible, but after
seeing dozens of "please keep your reply on list" responses recently,
I had to vent.
</rant>
Well, I hope you feel better now.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Jul 8 '07 #6
"Peter Decker" <py******@gmail.comwrites:
Imagine if you wrote applications where the default behavior did not
do what was needed 99% of the time: how long do you think you'd be
in business?
You seem to be complaining about the functionality of your mail user
agent (MUA) software. The mailing list processor is doing its job
fine.

There are at least two "compose a reply" functions supported by every
MUA. Use the one that does what you want in each instance.

If you use the "Reply to individual sender" function, that's what you
get.

If you use the "Reply to all" function, that's what you get.

If you use the "Reply to the list" function, that's what you get.
The default behavior of replying to the original sender instead of
the list makes no sense.
The mailing list software provides your MUA with all the information
it needs to do what you want: the 'From' address as set by the
original poster, the 'Reply-To' address as set by the original poster,
the 'To' and 'Cc' addresses as set by the original poster, and the
'List-Post' address as set by the mailing list software. All of these
are standard message header fields with well-defined functions, and
can be used as-is to do what you need.

If your MUA isn't using this information correctly, the solution is to
fix the MUA (by choosing a better one or encouraging the maker of your
existing one to fix it), not to munge those fields to accomodate your
broken MUA.

--
\ "Dyslexia means never having to say that you're ysror." -- |
`\ Anonymous |
_o__) |
Ben Finney
Jul 8 '07 #7
On 7/8/07, Ben Finney <bi****************@benfinney.id.auwrote:
"Peter Decker" <py******@gmail.comwrites:
Imagine if you wrote applications where the default behavior did not
do what was needed 99% of the time: how long do you think you'd be
in business?

You seem to be complaining about the functionality of your mail user
agent (MUA) software. The mailing list processor is doing its job
fine.
It's working as instructed, but that doesn't mean that it's doing the
best thing. It's common practice for mailing lists to set the reply-to
to the list itself, because that's the common case, and because it's
encouraged to keep discussion on the list.

If whoever manages the python lists doesn't want to do it, either
because they have some practical reason or because they've got a bug
up their ass about mail readers without list support, thats fine. But
it's hardly incorrect to configure it with the reply-to set to the
list, either.
Jul 9 '07 #8
En Mon, 09 Jul 2007 10:48:39 -0300, Chris Mellon <ar*****@gmail.com>
escribió:
It's working as instructed, but that doesn't mean that it's doing the
best thing. It's common practice for mailing lists to set the reply-to
to the list itself, because that's the common case, and because it's
encouraged to keep discussion on the list.

If whoever manages the python lists doesn't want to do it, either
because they have some practical reason or because they've got a bug
up their ass about mail readers without list support, thats fine. But
it's hardly incorrect to configure it with the reply-to set to the
list, either.
No, it's not correct to modify Reply-To. Some reasons:
http://www.unicom.com/pw/reply-to-harmful.html

--
Gabriel Genellina

Jul 9 '07 #9
On 7/9/07, Gabriel Genellina <ga*******@yahoo.com.arwrote:
En Mon, 09 Jul 2007 10:48:39 -0300, Chris Mellon <ar*****@gmail.com>
escribió:
It's working as instructed, but that doesn't mean that it's doing the
best thing. It's common practice for mailing lists to set the reply-to
to the list itself, because that's the common case, and because it's
encouraged to keep discussion on the list.

If whoever manages the python lists doesn't want to do it, either
because they have some practical reason or because they've got a bug
up their ass about mail readers without list support, thats fine. But
it's hardly incorrect to configure it with the reply-to set to the
list, either.

No, it's not correct to modify Reply-To. Some reasons:
http://www.unicom.com/pw/reply-to-harmful.html
None of those are reasons, they're opinions and weary old excuses. I'm
not necessarily saying munging is the correct thing to do (although,
personally, I support it and would prefer if the python lists did it)
but it's about a clash of opinions about what cases and behaviors
should be supported and encouraged. Since it's obviously not my call
as I'm not the admin of the python lists I adjust to what the list
does, but claiming that people asking for the other behavior are
incorrect or out of line in some way is just unjustified.
Jul 9 '07 #10
"Chris Mellon" <ar*****@gmail.comwrites:
On 7/9/07, Gabriel Genellina <ga*******@yahoo.com.arwrote:
No, it's not correct to modify Reply-To. Some reasons:
http://www.unicom.com/pw/reply-to-harmful.html

None of those are reasons, they're opinions and weary old excuses.
They're old, but not weary, because they're now supported by the
internet message standards, which spell out exactly what Reply-To and
List-Post are for.

<URL:http://woozle.org/~neale/papers/reply-to-still-harmful.html>

Reply-To, if used, is to be set by the message author. Since a
message transport system may only add fields to the header, not
arbitrarily modify existing fields, Reply-To can't be munged.
<URL:http://www.ietf.org/rfc/rfc2822.txt>

List-Post is to be used to give the email address for posting
messages to the mailing list.
<URL:http://www.ietf.org/rfc/rfc2369.txt>

Please, let's stop arguing what's already been decided. Every
behaviour you ask for is already supported by the existing
standards. The "common case" you speak of is fully supported by the
unambiguous List-Post field.

If your MUA is not using the information, provided in every message
from the mailing list, to do what you want, don't ask mailing list
admmministrators to accomodate your broken MUA.

--
\ "Pinky, are you pondering what I'm pondering?" "I think so, |
`\ Brain, but culottes have a tendency to ride up so." -- _Pinky |
_o__) and The Brain_ |
Ben Finney
Jul 10 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: serge | last post by:
We have an ASP application installed on one powerful Win 2003 and the SQL Server on another Win 2003. We have two copies of the application (identical, one for production and one for test...
0
by: LJ | last post by:
I have been getting this message and can't resolve the problem. I have checked the AntiVirus software and added the application directory to the exculsion list. The application is on a web farm,...
3
by: Jerry Boone | last post by:
I have a development unit running XP Pro and I cannot get it to build a web project without restarting IIS. There errors in the task list are.... ! Could not copy temporary files to the output...
4
by: Hari Koduru | last post by:
Hi All, I am getting the following exception in an ASP.NET application. Exception Details: System.InvalidOperationException: Application is restarting. I have been to the following Support...
1
by: Scott Lezberg | last post by:
We have an web application and the ASP .NET service keeps restarting for no apparent reason. I understand the recyclying concept and I see the event logged but is there any way to determine what...
7
by: GTi | last post by:
Does anyone have any good code for a self restarting application? Sometimes I need to exit my application and start it again, what is the best method of doing this in a windows form application....
9
by: walterbyrd | last post by:
I think I have read somewhere that using Python to develop web-applications requires some restarting of the Apache server, whereas PHP does not. Also, I seem to remember reading something about...
1
by: Adam Atlas | last post by:
What is the best way for a Python process (presumed to be a script run by the interpreter binary, not embedded in some other program) to restart itself? This is what I've been trying: import...
7
by: John | last post by:
Hi Is there a way to restart a winform app in case of a serious error? Thanks Regards
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.