Question

I wrote a program to resolve SubDomain using DNSPython library.
When the program is run and the sub domain resolved I write the exit handler to handle ctrlc signals:

def exitHandler(signum = 0, frame = 0):
    print("Kill Process..")
    os.kill(os.getpid(), 9)
    sys.exit(0)

If the user presses ctrlc the program doesn't terminate immediately and in some case the program gets locked!
How can I solve this problem?

Was it helpful?

Solution

When you use Ctrl-C on a Python process, it will end. There's no need to write your own exit handler, and there's certainly no need to try to kill your own process and then call sys.exit. This seems (literally) like over-kill.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top