Thread#abort_on_exception=true and exit(0)

A

Ara.T.Howard

i'd like a way to fork a child, while will have a heartbeat thread running
pinging the parent, partial example:

class Slave
def initialize
unless fork
Thread.abort_on_exception = true
Thread::new do
loop do
Process::kill 0, Process::ppid
sleep 42
end
end
yield
end
end
end

slave =
Slave::new do
loop do
FileUtils::touch 'sentinal'
sleep 42
end
end

in case it isn't clear, this slave dies if it's parent dies. in the real code
there is a method to kill the slave, the slave is detached, etc.

the thing is, i want the slave to execute 'exit!' not 'exit' on thread error
such that exit handlers do not get run.

any thoughts on how to do this?

perhaps redefining Kernel#exit in the slave?

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Thread#abort_on_exception=true and exit(0)"

|the thing is, i want the slave to execute 'exit!' not 'exit' on thread error
|such that exit handlers do not get run.
|
|any thoughts on how to do this?

How about wrapping everything in the

begin
... child ...
rescue Exception # catch all exception (including exit)
exit!
end

?

matz.
 
A

Ara.T.Howard

Hi,

In message "Re: Thread#abort_on_exception=true and exit(0)"

|the thing is, i want the slave to execute 'exit!' not 'exit' on thread error
|such that exit handlers do not get run.
|
|any thoughts on how to do this?

How about wrapping everything in the

begin
... child ...
rescue Exception # catch all exception (including exit)
exit!
end

?

matz.

perfect - i'll take it!

kind regards.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top