The file executor.py has the way to limit the memory usage of a subprocess. and using threads am able to limit the time for the subprocess. But the time is inefficient. It isn't stable for a subprocess for any 2 runs of the same command. To achieve this, I have to use /usr/bin/time command to get the exact time. and <bold>to limit time i have to have a shell script with threads in a line</bold>, rather than a subprocess call in python with threads. and the command I am using isn't simple as "python compute.py" it is something that is computed in this below specified form and is sent to subprocess.
compile_cmd = pathofexecutable + " " + source_file + ' < ' + input_file + ' 1> ' + output_file + ' 2> ' + error_file
main_command = /usr/bin/time -o timeoutputfile -f {'time':'%E', 'cpu':'%P', 'memory':'%M'} " + compile_cmd
The first line creates a python/perl file runnable command
the second line uses time command to get time and memory of the previous line
The thing is I am unable to limit time here, I was able to limit memory using the "setrlimit" of resource for subprocess. But unable to limit time for the shell command accurately.
@lamerman
"""
also getting the pid of a subprocess is possible only when the subprocess is on a run. and if you have a small command which executed in micro second, you cannot get the subprocess pid. though if you use an infinite loop and then try to get pid it is possible. But the subprocess pid is the pid of the subprocess parent class object not the child shell process. Hence even if you get the pid it isn't efficient.
Hi, @lamerman !
Example of error traceback:
Traceback (most recent call last):
File "/tmp/shellpy_root/root/cr/scripts/monitor.py", line 272, in <module>
some_error_line
NameError: name 'some_error_line' is not defined
But, actually, 'some_error_line' is line 262, not 272
Is it possible "compile" to python with same lines numbers as in .spy file?
^CTraceback (most recent call last):
File "/tmp/shellpy_root/root/cr/scripts/monitor.py", line 272, in <module>
Traceback (most recent call last):
File "/usr/bin/shellpy", line 9, in <module>
load_entry_point('shellpy==0.4.5', 'console_scripts', 'shellpy')()
File "/usr/lib/python2.7/site-packages/shellpython/shellpy.py", line 40, in main
main()
retcode = subprocess.call(processed_file + ' ' + ' '.join(script_args), shell=True, env=new_env)
File "/usr/lib64/python2.7/subprocess.py", line 524, in call
File "/tmp/shellpy_root/root/cr/scripts/monitor.py", line 269, in main
watchgod()
File "/tmp/shellpy_root/root/cr/scripts/monitor.py", line 232, in watchgod
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 1376, in wait
sleep(30)
KeyboardInterrupt
pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
File "/usr/lib64/python2.7/subprocess.py", line 478, in _eintr_retry_call
return func(*args)
KeyboardInterrupt