if at the end of the code i write this o execute main,

if __name__ == '__main__':
    except KeyboardInterrupt:

isnt thre anyyy other way to exit the interpretor except pressing ctrl -c ???? the interpretor halts even if code ends and then i have to press ctrl c to exit it ... plz tel me some other way out, to automatically terminate the code.

If you invoke the python interpreter from the command line, like this: python and then type in the small program, then "no" you exit the interpreter with a control key (unix and unix-like shells, it is Ctrl-D, don't know in Windows)

If, on the other hand, you put your program in a text file and invoke the python interpreter like this python scriptfilename then the interpreter returns to the shell command line when the script is finished.

Does that answer your question?

Also, if you want to exit from a deeply nested point during the execution you can use

raise SystemExit


import sys
sys.exit(0) # use another value, like -1 to mean program failure

raise any error and then don't handle it will quit your program.

But it's best to use sys.exit

basically i am working on GNU radio, python....

i am trying to end up the code benchmark_rx.py automatically when the whole file is received, without pressing ctrl c.

any 1 of u working on gnuradio?

thanx to all for your replies.. ill try all these suggestions n will let u know soon.. thnx..

The nice thing about using
raise SystemExit
to exit your program is that you don't have to import anything extra.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.