From: Robert Klemme Date: 2006-09-11T14:40:23+09:00 Subject: Re: Thread, external processes, and trap James Mills wrote: > In order to ensure that I have an external process to send information > to, I spawn it and watch it from within the ruby controller. I also > want to keep an eye on it and re-spawn it if needed. So basically I > used Thread.new twice. The first thread is the process "watcher" > which spans the actual process thread. Once it does this, the watcher > thread sleeps until the process thread exits. If the process does > exit for some reason, the watcher thread will respawn it a > configurable number of times. > 3) watcher and proc threads up and running. I kill the external > process manually, and the watcher respawns it. I press ^C - The > process thread is killed and the watcher catches and respawns it! The > trap code is never executed!!!! That's probably because a) the trap block is executed in the context of the watcher thread and b) exit uses an exception to terminate the process: robert@fussel /cygdrive/c/Temp $ ruby -e 'begin exit; rescue Exception => e; p e end' # robert@fussel /cygdrive/c/Temp $ ruby -e 'puts SystemExit.ancestors' SystemExit Exception Object Kernel I guess you catch Exception in your watcher and not something more specific. You should probably either catch more selective or check the exception and act accordingly in your watcher thread. Kind regards robert