Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
(bbfu) (nested limits) Re: Perl syntax for enforcing time limitsby bbfu (Curate) |
on Apr 30, 2001 at 07:34 UTC ( [id://76540]=note: print w/replies, xml ) | Need Help?? |
An interesting module, and implemented well. As constructive critisim, there's two things I'd like to mention. First, and simplest, you document a return value of undef on timeout but you actually return 0. This can trip people up so you might want to fix it. Second, I think that, perhaps, you're handling nested time_limit()'s incorrectly (not that I really know what I mean by "correct"). Consider:
The output of this test program is:
Whereas anyone looking at the outter time_limit() would think that it should return no more than 3s later. (Imagine the inner time_limit() call being burried in a called subroutine...) Further, what if the code you expected to cause a timeout was after the inner time_limit() call? Because your code actually resets the alarm(), it could take even longer. Of course, for most applications where you would want to time_limit() some code, you wouldn't really care if it takes a little bit longer to time out than you expected, so it shouldn't matter much. Also, I can't think of a very elegant solution that would handle such cases. I never did understand why they limited it to one alarm per process... Well, I hope that at least gives you some ideas to work with. In fact, I think I might just have to look into writing a module that would offer a more robust replacement for alarm. :-) And again, congrats on a good module. Happy coding. bbfu
In Section
Craft
|
|