Julia 0.4.7:如何捕获SIGTERM

时间:2016-12-02 17:33:32

标签: julia sigterm

我在julia-0.4.7脚本中的SIGTERM(非SIGINT)事件之后得到以下stacktrace:

signal (15): Terminate
write at /lib64/libpthread.so.0 (unknown line)
unknown function (ip: 0x2ade16a02893)
uv_write2 at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
jl_uv_write at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
uv_write at ./stream.jl:951
buffer_or_write at ./stream.jl:972
write at ./stream.jl:1011
print at ./char.jl:47
unknown function (ip: 0x2ade1e06d0a2)
jl_apply_generic at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
print at strings/io.jl:18
jl_apply_generic at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
jl_f_apply at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
println at strings/io.jl:25
jl_apply_generic at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
anonymous at /path/to/home/test.jl:4
unknown function (ip: 0x2ade169c5b13)
unknown function (ip: 0x2ade169c672c)
jl_load at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
include at ./boot.jl:261
jl_apply_generic at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
include_from_node1 at ./loading.jl:333
jl_apply_generic at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
process_options at ./client.jl:284
_start at ./client.jl:378
unknown function (ip: 0x2ade1e05ae79)
jl_apply_generic at /path/to/home/julia/bin/../lib/julia/libjulia.so (unknown line)
unknown function (ip: 0x401c87)
unknown function (ip: 0x40186f)
__libc_start_main at /lib64/libc.so.6 (unknown line)
unknown function (ip: 0x4018b5)

那么,我怎么抓住它?在我的Julia二进制文件中看起来像是坏了,不是吗?有没有像SIGINT一样捕获SIGTERM的方法?即:

ccall(:jl_exit_on_sigint, Void, (Cint,), 0)
try
    ...
catch ex
    println("caught something")
    if isa(ex, InterruptException)
        println("it was an interrupt")
    end
end

我使用的是Cent-OS 6.5。

1 个答案:

答案 0 :(得分:0)

简短回答:你不能,见here。你引用的东西,jl_exit_on_sigint是用julia/src/signal-handling.c编写的C函数。目前,他们还没有为SIGTERM编写处理程序,因此添加自己的处理程序意味着更改Julia的基础,并且他们没有公开任何用于处理信号的API。这主要是因为没有一种方法可以在没有大的性能损失的情况下在线程之间进行信号处理的一致方式。