On 2015-05-11, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > On Mon, 11 May 2015 09:57 pm, Dave Angel wrote: > >> On 05/11/2015 07:46 AM, Skybuck Flying wrote: >>> Hello, >>> >>> Sometimes it can be handy to "interrupt/reset/reposition" a running >>> script. >>> >>> For example something externally goes badly wrong. >>> >> >> os.kill() >> >> then in your process, handle the exception, and do whatever you think is >> worthwhile. > > > Are you suggesting that the app sends itself a signal? > > Is that even allowed?
Of course (at least on Unix/Linux/Posix systems). And there's even a special case defined to make sending signals to yourself easy: you just send them to PID 0. >From "man 2 kill" on Linux: DESCRIPTION The kill() system call can be used to send any signal to any process group or process. [...] If pid equals 0, then sig is sent to every process in the process group of the calling process. And just to make sure I ran a little test, and it works exactly as advertised: ---------------------------------testit.py-------------------------------- #!/usr/bin/python import os, sys, time, threading, signal def thread1(): while True: sys.stdout.write("Hello %s\n" % time.time()) time.sleep(1) threading.Thread(target=thread1).start() time.sleep(2) os.kill(0,signal.SIGKILL) --------------------------------------------------------------------------- $ ./testit.py Hello 1431354383.19 Hello 1431354384.19 Killed $ -- Grant Edwards grant.b.edwards Yow! Hello. Just walk at along and try NOT to think gmail.com about your INTESTINES being almost FORTY YARDS LONG!! -- https://mail.python.org/mailman/listinfo/python-list