yes. forkoff has a number of consumer *green* threads used to manage an array of queues containing the elements destined to be passed to a forked process/native thread for execution of the block. the code is very short, give a read.
On Apr 29, 2008, at 4:15 PM, Abdul-rahman Advany wrote:
Sorry, just figured out calling fork makes the thread a child process...
just need to find out how to set a timeout on the thread... anyone
suggestions?
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
That'll kill the thread, but not the child process that was forked, at least
that's what I remember.
Try this as a general strategy:
parent_t = Thread.new(cmd) do |exec_me|
if cpid = fork then
Thread.current[:cpid] = cpid
cpid, exit_status = Process.waitpid2(cpid)
Thread.current[:exit_status] = exit_status
else
exec exec_me
end
end
unless parent_t.join( seconds ) # seconds contains your timeout value
cpid = parent_t[:cpid]
%w[ TERM KILL ].each do |sig|
Process.kill(sig, cpid)
break if parent_t.join(1)
end
# Do something with Thread.current[:exit_status] to report the child
# process exit status.
enjoy,
-jeremy
···
On Wed, Apr 30, 2008 at 08:02:36AM +0900, ara.t.howard wrote:
On Apr 29, 2008, at 4:15 PM, Abdul-rahman Advany wrote:
Sorry, just figured out calling fork makes the thread a child process...
just need to find out how to set a timeout on the thread... anyone
suggestions?
require 'timeout'
begin
Timeout.timeout(seconds){ thread.join }
rescue Timeout::Error
thread.kill rescue nil
end