0

I want to enforce timeout of 5s to python command and at the same time want to measure the execution time for python command (taking into account that python3 command memory limit is 256 MB), what I am doing is

ulimit -v 256000 && /usr/bin/time -f \"TIME: %e\" timeout 5s python3 test.py 2>&1

Above command is setting the virtual memory to 256 MB so that python3 command don't exceed above 256 MB, also I am measuring the time using /usr/bin/time and setting the timeout to 5s for python3 command.

I am in doubt that timeout is enforced on python3 command but the time command is put upon timeout as well as python3 command. But I want to set time only only python3 command. As above command will give time for timeout and python3 command execution but I want execution time for python3 command only.

Note: I want all of these actions to occur in a single line, as that is my requirement.

If there are any commands available that can accomplish the above tasks, that would also be acceptable.

3
  • a) did you try timeout 5s /usr/bin/time -f \"TIME: %e\" python3 test.py ? b) execution time of timeout command would be very small. Commented Jun 5, 2023 at 13:02
  • @Archemar then timeout is set upon time and python3 command as a whole, which doesn't truly set timeout on python3 execution only! Although timeout execution is very small but I want to set timeout and time only for python3 command, not any command pipeline. Commented Jun 5, 2023 at 13:10
  • I don't think this is going to work. You will either timeout the time along with python or time the timeout along w/ python. Having both apply to ONLY python looks impossible to me. Commented Jun 7, 2023 at 2:34

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.