Timeout-lib, which interrupts everything, also systemcalls. It uses libc-alarm.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Denis Knauf f963e41c52 „README.md“ ändern 2 months ago
lib small minor warnings fixed (unused vars, ...). comments. 5 months ago
test reimplement tests and minor fixes. 5 months ago
.gitignore .document removed and ignored 5 months ago
Gemfile dependencies: need should, test-unit for testing. but no rspec. 5 months ago
LICENSE.txt Version bump to 0.1.1 9 years ago
README.md „README.md“ ändern 2 months ago
Rakefile reimplement tests and minor fixes. 5 months ago
VERSION Version bump to 0.3.0 9 years ago
timeout-interrupt.gemspec dependencies: need should, test-unit for testing. but no rspec. 5 months ago

README.md

timeout-interrupt

Works like ruby's timeout, but interrupts every call, also syscalls, which blocks the hole ruby-process.

It uses POSIX's alarm and traps ALRM-signals.

Known limitations bacause of alarm and ALRM are, that you can not use alarm or trap ALRM in the same time.

Scopes

If you need scopes with inner and outer time outs, you should know:

The first timed out Timeout will be raised:

include TimeoutInterrupt
timeout(1) { # Will be raised
	timeout(10) { sleep 2 } # Will not be raised
}

If you want to know, which was raised, you need custom exceptions:

class CustomErrorWillBeRaised <Exception
end
class CustomErrorNotRaised <Exception
end
include TimeoutInterrupt
timeout( 1, CustomErrorWillBeRaised) { # Will be raised again
	timeout( 10, CustomErrorNotRaised) { sleep 2 } # Will not be raised
}

Problems

Memory-Leaks and missing clean up

Syscalls can allocate memory. If you interrupt a syscall, which then cannot free his allocations, it will result in a memory leak. If it opens a file, while it reads, a time out occurs, the file will not automatically be closed.

So, you should only use it, if your process will die after interrupt or if you are sure, that your call never allocate memory or opens a file. You could also publish informations about opened files, that it could be cleaned up later.

Every time, a process dies, all his memory will be freed and every file will be closed, so let your process die and you should be safe.

Exception-handling

Timeouts can break your exception-handling! You should not handling exception while you wait for a timeout:

include TimeoutInterrupt
timeout(1) {
	begin
        transaction_begin
        do_something
	ensure
        clean_up
        transaction_end
	end
}

Same happens, if clean_up will raise an exception, so handle it in the same way.

And same problem you have with ruby's Timeout.timeout.

Copyleft

Copyright (c) 2021 Denis Knauf. See LICENSE.txt for further details.