[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash vs. python scripts - which one is better?



On 2007-08-12 00:57:22 +0100, William Pursell wrote:
> Here is a method for doing a timeout.  I'm not arguing against
> the claim that sh is limited, nor am I claiming that the method
> presented here is robust (it doesn't work well if the function
> has already completed, for example), but this certainly demonstrates
> that it is possible to execute a command with a timeout.
[...]

The timeout function keeps waiting even after the command has completed
(when it has completed before the timeout, which is the normal case),
and this is a real efficiency problem. Of course, I think that one can
replace your "sleep $timeout" by a loop that would poll every second,
but this is rather inelegant and possibly inefficient. Moreover, there
is a possible race condition; I suppose that this can also be solved by
trapping SIGCHLD.

Also, if one wants to interrupt the script by Ctrl-C for instance,
this doesn't work well (the command is not killed).

-- 
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)



Reply to: