Restart crashing modules in windows

Mike Driscoll kyosohma at gmail.com
Tue Jan 15 20:51:49 EST 2008


On Jan 15, 2008 5:08 PM, Astan Chee <stanc at al.com.au> wrote:
>
>  Mike Driscoll wrote:
>  On Jan 14, 9:02 pm, Astan Chee <st... at al.com.au> wrote:
>
>
>  Hi,
> I have a python module that keeps on crashing with various windows
> errors (not BSOD but the less lethal windows XP popup ones). Now these
> are intentional and rather sporadic so I cant really solve it by
> attempting to fix the crash; rather what Im trying to do is make another
> module outside it that restarts this module every time it crashes. Is
> this possible?
>
>  If you're not going to catch the error that is causing the crash, then
> I think your only option is to restart your application with an
> external program.
>
>  My understanding of using an external application to do this is to first
> create my module as an executable using py2exe. Then I have another python
> script that runs this module like this
>
>  while (1):
>      os.popen("program_module.exe")
>
>  and make this other python script into another executable and execute this
> one. If Im not mistaken, when the python program crashes, the thread is
> killed. is this correct or how should I do it?
>  Thanks again.
>  Astan
>

You'll have to look in Windows Task Manager and see if your
"program_module.exe" is listed after the crash. Press CTRL+Shift+ESC,
right-click a blank spot on the taskbar and choose Task Manager or
press CTRL+ALT+DEL to open it. If your program is not listed, then the
thread is "killed" so-to-speak. Otherwise, it's most likely hung and
you'll have to select it and choose End Process to kill it.

If it is not hung, then you can use the os.popen method to restart it,
but you should really look at subprocess.Popen() instead as it
supersedes os.popen() as of Python 2.4. See http://docs.python.org/lib/module-subprocess.html
for more info.

You might also take a look at IDLE's code as it has a way of stopping
a script using CTRL+C and restarting itself into its original state.

Mike



More information about the Python-list mailing list