Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90385

Re: Feature Request: Reposition Execution

From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: Feature Request: Reposition Execution
Date 2015-05-11 14:27 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <miqe9a$r2r$1@reader1.panix.com> (permalink)
References <2d482$5550967d$5419aafe$27910@news.ziggo.nl> <mailman.354.1431345441.12865.python-list@python.org> <5550a223$0$13013$c3e8da3$5496439d@news.astraweb.com>

Show all headers | View raw


On 2015-05-11, Steven D'Aprano <steve+comp.lang.python@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!!

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Feature Request: Reposition Execution "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-11 13:46 +0200
  Re: Feature Request: Reposition Execution Dave Angel <davea@davea.name> - 2015-05-11 07:57 -0400
    Re: Feature Request: Reposition Execution Marko Rauhamaa <marko@pacujo.net> - 2015-05-11 15:02 +0300
    Re: Feature Request: Reposition Execution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-11 22:35 +1000
      Re: Feature Request: Reposition Execution Dave Angel <davea@davea.name> - 2015-05-11 09:21 -0400
      Re: Feature Request: Reposition Execution Grant Edwards <invalid@invalid.invalid> - 2015-05-11 14:27 +0000
    Re: Feature Request: Reposition Execution "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-12 22:18 +0200
      Re: Feature Request: Reposition Execution Christian Gollwitzer <auriocus@gmx.de> - 2015-05-13 09:27 +0200
        Re: Feature Request: Reposition Execution Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-13 19:07 +1000
          Re: Feature Request: Reposition Execution "Skybuck Flying" <skybuck2000@hotmail.com> - 2015-05-15 05:58 +0200
            Re: Feature Request: Reposition Execution Christian Gollwitzer <auriocus@gmx.de> - 2015-05-15 08:06 +0200

csiph-web