So I'm running a Julia (v 0.6.3) script in a bash script called ./run.sh
like so:
./julia/bin/julia scripts/my_script.jl
Now the script prematurely terminates. I'm sure of this because it doesn't finish outputting all the data it's supposed to. When I run a parsing script (written in Python) afterwards, it fails because of missing data.
I think that it terminates to insufficient RAM allocation (I'm running the script on a Docker container). If I bump up the allocated RAM the script works fine.
To catch this error in my Julia script I did the following:
try main();
catch e
println(e)
exit(1)
end
exit(0)
On top of that, I updated the bash script to check if the Julia script failed:
./julia/bin/julia scripts/my_script.jl
echo "Julia script returned: $?"
if [ $? -ne 0 ]; then
echo "Julia script failed"
exit 1
fi
However, no exception is printed from the Julia script. Furthermore, the return code is 0
, so the bash bash script doesn't detect any errors either.
If I just run the the script directly from the terminal, at the very end of the output there's the word Killed
. Immediately after I ran the command echo $?
and I get 137
, which is definitely not a successful return status. So it seems Julia and bash both know the script is terminated, but not if I run the Julia script from within a bash script...?
Another weird thing is when I run the Julia script from the bash script, the word Killed
doesn't appear at all!
How can I reliably detect whether a script was prematurely terminated? Is there a way to get the reason it was killed as well (e.g. not enough RAM, stack overflow, etc)?
[ $? -ne 0 ]
:$?
contains return code of last command. Here fromecho
and not fromjulia
. – Cyrus