From: Back9 on
Hi,

I run my py app to display a file's contents, and it is normally very
long.
So I use it like below:

python myapp.py input_file | more
to see them step by step.

But when I try to exit it, normally I use Ctrl+ C key to quit it.
Problem is every time I do like it, it shows Traceback message and it
makes my app not professional.

How do I handle it gracefully.

TIA
From: Tim Harig on
On 2010-08-11, Back9 <backgoodoo(a)gmail.com> wrote:
> python myapp.py input_file | more
> to see them step by step.
>
> But when I try to exit it, normally I use Ctrl+ C key to quit it.
> Problem is every time I do like it, it shows Traceback message and it
> makes my app not professional.

You have three options.

1. Exit more properly.

2. Catch and handle SIGINT yourself.

3. Wrap whatever section of your program is being interrupted in
try/except to catch the KeyboardInterrupt exception when it
is generated.
From: Jean-Michel Pichavant on
Back9 wrote:
> Hi,
>
> I run my py app to display a file's contents, and it is normally very
> long.
> So I use it like below:
>
> python myapp.py input_file | more
> to see them step by step.
>
> But when I try to exit it, normally I use Ctrl+ C key to quit it.
> Problem is every time I do like it, it shows Traceback message and it
> makes my app not professional.
>
> How do I handle it gracefully.
>
> TIA
>
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print 'Hey ! this is a professional application'

Cheers,

JM



From: Back9 on

On Aug 11, 11:19 am, Tim Harig <user...(a)ilthio.net> wrote:
> On 2010-08-11, Back9 <backgoo...(a)gmail.com> wrote:
>
> > python myapp.py input_file | more
> > to see them step by step.
>
> > But when I try to exit it, normally I use Ctrl+ C key to quit it.
> > Problem is every time I do like it, it shows Traceback message and it
> > makes my app not professional.
>
> You have three options.
>
>         1. Exit more properly.
>
>         2. Catch and handle SIGINT yourself.
>
>         3. Wrap whatever section of your program is being interrupted in
>                 try/except to catch the KeyboardInterrupt exception when it
>                 is generated.

I should have mentioned that I already use try/except
KeyboardInterrupt statement.
But it does not seem to work as I expected.

TIA
From: Michael Torrie on
On 08/11/2010 09:32 AM, Back9 wrote:
> I should have mentioned that I already use try/except
> KeyboardInterrupt statement.
> But it does not seem to work as I expected.

If you want anyone to help further, you will need to say a) what you are
expecting it to do and b) what it is actually doing.