Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16544 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2011-12-03 02:13 +1100 |
| Last post | 2011-12-07 11:50 -0800 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Multiprocessing: killing children when parent dies Chris Angelico <rosuav@gmail.com> - 2011-12-03 02:13 +1100
Re: Multiprocessing: killing children when parent dies 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-02 07:57 -0800
Re: Multiprocessing: killing children when parent dies 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-02 07:57 -0800
Re: Multiprocessing: killing children when parent dies Chris Angelico <rosuav@gmail.com> - 2011-12-03 03:14 +1100
Re: Multiprocessing: killing children when parent dies 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-02 08:27 -0800
Re: Multiprocessing: killing children when parent dies 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-02 08:27 -0800
Re: Multiprocessing: killing children when parent dies Dan Stromberg <drsalists@gmail.com> - 2011-12-07 11:50 -0800
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-12-03 02:13 +1100 |
| Subject | Re: Multiprocessing: killing children when parent dies |
| Message-ID | <mailman.3224.1322838818.27778.python-list@python.org> |
On Sat, Dec 3, 2011 at 2:05 AM, Mihai Badoiu <mbadoiu@gmail.com> wrote: > In the multiprocessing module, on a Process p, by just doing p.daemon=1 > before p.start(), we can make the child die when the parent exits. However, > the child does not die if the parent gets killed. > How can I make sure the child die when the parent gets killed? Are you in control of the killing of the parent? One easy way would be to catch the signal (say SIGINT) and initiate an orderly shutdown, signalling the children first. ChrisA
[toc] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-12-02 07:57 -0800 |
| Message-ID | <mailman.3227.1322841479.27778.python-list@python.org> |
| In reply to | #16544 |
On Friday, December 2, 2011 11:13:34 PM UTC+8, Chris Angelico wrote: > On Sat, Dec 3, 2011 at 2:05 AM, Mihai Badoiu <mba...@gmail.com> wrote: > > In the multiprocessing module, on a Process p, by just doing p.daemon=1 > > before p.start(), we can make the child die when the parent exits. However, > > the child does not die if the parent gets killed. > > How can I make sure the child die when the parent gets killed? > > Are you in control of the killing of the parent? One easy way would be > to catch the signal (say SIGINT) and initiate an orderly shutdown, > signalling the children first. > > ChrisA Multiple thread supporting programming languages in true OOP as Erlang and Python do not talk about POSIX signals.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-12-02 07:57 -0800 |
| Message-ID | <31747430.412.1322841476524.JavaMail.geo-discussion-forums@prfx15> |
| In reply to | #16544 |
On Friday, December 2, 2011 11:13:34 PM UTC+8, Chris Angelico wrote: > On Sat, Dec 3, 2011 at 2:05 AM, Mihai Badoiu <mba...@gmail.com> wrote: > > In the multiprocessing module, on a Process p, by just doing p.daemon=1 > > before p.start(), we can make the child die when the parent exits. However, > > the child does not die if the parent gets killed. > > How can I make sure the child die when the parent gets killed? > > Are you in control of the killing of the parent? One easy way would be > to catch the signal (say SIGINT) and initiate an orderly shutdown, > signalling the children first. > > ChrisA Multiple thread supporting programming languages in true OOP as Erlang and Python do not talk about POSIX signals.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-12-03 03:14 +1100 |
| Message-ID | <mailman.3228.1322842458.27778.python-list@python.org> |
| In reply to | #16550 |
On Sat, Dec 3, 2011 at 2:57 AM, 88888 Dihedral <dihedral88888@googlemail.com> wrote: > Multiple thread supporting programming languages in true OOP as Erlang and Python do not talk about POSIX signals. The OP talked about multiprocessing. Each thread of execution is a separate context, and can receive signals. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-12-02 08:27 -0800 |
| Message-ID | <mailman.3229.1322843240.27778.python-list@python.org> |
| In reply to | #16551 |
Please check Erlang that spawn so easily. And there are Python packages can do the same task.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2011-12-02 08:27 -0800 |
| Message-ID | <27696236.393.1322843237576.JavaMail.geo-discussion-forums@prfb10> |
| In reply to | #16551 |
Please check Erlang that spawn so easily. And there are Python packages can do the same task.
[toc] | [prev] | [next] | [standalone]
| From | Dan Stromberg <drsalists@gmail.com> |
|---|---|
| Date | 2011-12-07 11:50 -0800 |
| Message-ID | <mailman.3384.1323287403.27778.python-list@python.org> |
| In reply to | #16553 |
On 12/7/11, Mihai Badoiu <mbadoiu@gmail.com> wrote: > ok, so the code is something like > #process A > p = Process(...) > p.daemon = 1 > p.start() # starts process B > ... > > If process A dies (say error, or ctrl-c), or finishes, then process B also > dies. But if process A is killed with the "kill" command, then process B > soldiers on... > > Any idea on how to make process B die when process A gets killed by the > "kill" command? 1) If all you care about is SIGTERM, SIGHUP and the like (and specifically NOT SIGKILL), you could just install a signal handler that catches any catchable signals you're interested in. Then the signal either kills the children directly, or sets a flag that tells the main process to do some killing shortly. Note that threads and signal handlers don't mix very well - the combination tends to make the main thread immune to control-C, whether you want it to be or not. Also, signal handlers tend to complicate performing I/O, as you're more likely to read short blocks. 2) If you need to handle SIGKILL gracefully, and you have access to the code of the child process, you could make sure that the child isn't setting a SID (?). ssh, I believe, likes to start a new SID, making it immune to signals to the parent. Alternatively, you could add something to the child process' main loop that polls the parent, exiting if the parent no longer exists. 3) If you need to handle SIGKILL gracefully, and you don't have access to the code of the child process, you could use a single extra process that checks for the presense of the parent, and if it doesn't exist any more, then kill the children before exiting itself.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web