Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top