Stop Python from exiting upon error in Windows

John Roth newsgroups at
Tue Jul 15 16:40:34 CEST 2003

"Conrad" <zneptune321 at zexcite.zcom> wrote in message
news:pan.2003. at zexcite.zcom...
> Years ago, Nostradamus predicted that on Mon, 14 Jul 2003 20:06:14 -0700,
> Tom Plunket would write, saying:
> > Robert wrote:
> >
> >> How can I stop the Python interpreter from exiting when an error
> >
> > create a batchfile, tell Windows that the association of Python
> > files is to that batch file, and put this in the file:
> >
> > python.exe %1
> > pause
> >
> >
> > Or- catch the error in your mainline, and do a sys.raw_input()
> > call on exception.
> >
> > -tom!
> Or the third, and admittedly brute force solution
> I use is to fire up the DOS shell, (click on START,
> then RUN, then type "command"). Depending on which
> Win you're running, you may want to run DOSKEY,
> which lets you cursor back up to previous commands.
> Once you've got the command window up (and doskeyed),
> cd to your python source directory, and type in
> something like *C:\python22\python.exe*
> (leave out the *s and be sure python is in the same
> place on your machine.)
> This doesn't keep the python interpreter from exiting,
> but it does keep the DOS window open to let you see
> your error messages.
> I admit it's ugly, but hey, I mostly develop in
> FreeBSD and Linux, where the CLI is your buddy ;-)

It may be ugly, but that's how I develop on my system
(currently Windows XP, was 98SE until last week.)

You don't have to put in the full path to Python if you
rig the command prompt you're using to add Python to
the path as the initialization command. That trick should
also let you set up PYTHONPATH for the project.

I keep a command prompt instance in each project
directory, pointing to the correct initialization for the
project. Then I've got a small batch file for each test
module. A mouse click to switch windows, three
key strokes and voila! the test runs (or not, as the
case may be.) It avoids any possible problem with
PythonWin polluting itself by not refreshing everything
on a retest. I can't speak for Idle, but I think it's got
some of the same problems of not isolating the program
under test.

John Roth
> Conrad

More information about the Python-list mailing list