Re: Non-Threaded Timeout?



Hi Ara,

I agree that the *principal* of the idea is about the only one to pursue
on Windows. I tried the following code:

def timeout seconds, key, &block
pid = Process.pid
signaler = IO.popen "ruby -e'sleep #{ seconds };
Process.kill(:#{key}.to_s, #{ pid }) rescue nil'"
handler = Signal.trap(key){ raise 'timed out...' }
begin
block.call
ensure
Process.kill key, signaler.pid rescue nil
Signal.trap(key, handler)
end
end

Signal.list.keys.each do |key|
puts key
unless key == 'KILL'
timeout(2, key) { p 'works' }
timeout(1, key) { sleep 2; p 'does not work' }
end
end

and it produced the following output:

ruby timeout_test.rb
TERM
"works"
"does not work"
SEGV
"works"
"does not work"
KILL
EXIT
"works"
"does not work"
INT
"works"
"does not work"
FPE
"works"
"does not work"
ABRT
"works"
"does not work"
ILL
"works"
"does not work"
Exit code: 0

--
Thanks!
Bryan

Ara Howard wrote:
did you try the 'INT' signal? there are only a few signals supports
in windows between process and i forget which is which. in any case,
even if that exact code will not work the *principle* will: that of
setting up an external process to do something to your (potentially
blocked) process. in fact it's the only way out when you consider
ruby's thread impl.

--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: OE Generates c0000005 (access violation) How to correct?
    ... You really should visit the Windows Update page to update your system to SP2 ... >> George Hester ... The PID changes so using ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: CPU pegs near 100%, mysterious log entry
    ... For some mysterious reason Windows has been busy resynching the mirror drive. ... This is Windows RAID (I decided I could not trust the motherboard's built in Raid after a few days of trying the machine way back when. ... Now, I don't know whether it is resynching because of the hard shutdown, or because of something that happened before I had to do a hard reboot. ... I had tried the tasklist /svc for the svchost.exe PID but it wast not very helpful. ...
    (microsoft.public.windows.server.sbs)
  • Re: Windows XP WMI Reinstall
    ... c:\>tlist -s | findstr /i winmgmt ... This posting is provided "AS IS" with no warranties, and confers no rights. ... > Facility: Windows ... I couldn't get a PID for the winmgmts process because it's not ...
    (microsoft.public.win32.programmer.wmi)
  • A Proposed New Principle of Mathematics
    ... I propose today a new arithmetic principle, say PId, ... To know whether a given number is even or odd, ... Now, by the look of it, is in no way an expression of FOL framework: ...
    (sci.logic)
  • Re: Different Kerberos Principals from Windows Login
    ... I logged into a W2K pro and a Windows XP workstation with a new account ... reported my principle as username@southpark.colorado on all tests. ... Perhaps something unique on the user account. ... If they use a different login ...
    (microsoft.public.windows.server.security)