Iβm not able to capture correctly the SIGINT
signal and invoke a controlled shutdown.
It seems that atexit
should be the answer, but in my (semplified) minimal example, with FileWatching
:
using FileWatching
function watch(dir::String)
try
while true
filename, event = watch_folder(dir, -1.0)
@info "[$filename] event: $event"
end
catch e
@warn "error watchdir: $e"
end
end
function shutdown(dir::String)
@info "stop watching $dir"
unwatch_folder(dir)
end
dir = "/tmp"
shtdown() = shutdown(dir)
atexit(shtdown)
watch(dir)
I expect that before exiting the process will invoke shutdown, unwatch the folder and exit.
Instead this is what happens with Ctrl-C
:
signal (2): Interrupt
in expression starting at /home/adona/dev/SINT/sint/sintjl/Sint/mve.jl:25
epoll_pwait at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
uv__io_poll at /workspace/srcdir/libuv/src/unix/linux-core.c:270
uv_run at /workspace/srcdir/libuv/src/unix/core.c:359
jl_task_get_next at /buildworker/worker/package_linux64/build/src/partr.c:473
poptask at ./task.jl:704
wait at ./task.jl:712 [inlined]
wait at ./condition.jl:106
take_buffered at ./channels.jl:387
take! at ./channels.jl:381 [inlined]
wait at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/FileWatching/src/FileWatching.jl:620
watch_folder at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/FileWatching/src/FileWatching.jl:747
watch at /home/adona/dev/SINT/sint/sintjl/Sint/mve.jl:6
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2231 [inlined]
...
Allocations: 2544 (Pool: 2533; Big: 11); GC: 0
[ Info: stop watching /tmp
β Error: Exception while generating log record in module Main at /home/adona/dev/SINT/sint/sintjl/Sint/mve.jl:15
β exception =
β schedule: Task not runnable
β Stacktrace:
β [1] error(::String) at ./error.jl:33
β [2] schedule(::Task, ::Any; error::Bool) at ./task.jl:591
β [3] schedule at ./task.jl:586 [inlined]
β [4] uv_writecb_task(::Ptr{Nothing}, ::Int32) at ./stream.jl:1051
β [5] poptask(::Base.InvasiveLinkedListSynchronized{Task}) at ./task.jl:704
β [6] wait at ./task.jl:712 [inlined]
β [7] uv_write(::Base.TTY, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:933
β [8] unsafe_write(::Base.TTY, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:1005
β [9] unsafe_write at ./io.jl:622 [inlined]
β [10] write(::Base.TTY, ::Array{UInt8,1}) at ./io.jl:645
β [11] handle_message(::Logging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::String, ::Module, ::Symbol, ::Symbol, ::String, ::Int64; maxlog::Nothing, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Logging/src/ConsoleLogger.jl:161
β [12] handle_message at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/Logging/src/ConsoleLogger.jl:100 [inlined]
β [13] macro expansion at ./logging.jl:332 [inlined]
β [14] shutdown(::String) at /home/adona/dev/SINT/sint/sintjl/Sint/mve.jl:15
β [15] shtdown() at /home/adona/dev/SINT/sint/sintjl/Sint/mve.jl:21
β [16] _atexit() at ./initdefs.jl:316
β @ Main ~/dev/SINT/sint/sintjl/Sint/mve.jl:15
a
FileWatching
is just my first problem, after that will be db connections and sockets to close β¦
How to manage correctly an ordered shutdown in this scenario?