I cannot say where the evil comes from but when I like to use the atexit() function,
which you can found here in the docs I got these three kinds of error messages:
-
ErrorException(“schedule: Task not runnable”)
-
OutOfMemoryError
atexit hook threw an error: OutOfMemoryError() -
ErrorException
atexit hook threw an error: ErrorException(“schedule: Task not runnable”)
when running the following code in a script in background
#redirect stderr to put in a file later
orig_stderr = STDERR
(err_read, err_write) = redirect_stderr()#do cleaning at exit
atexit(function()redirect_stderr(orig_stderr) println("Start cleaning ...") error_date = now() println("start error writing to file") close(err_write) error_name = string("/path_to_error_dir/",error_date) f = open(error_name,"w") write(f, readavailable(err_read)) close(f) close(err_read) println("... finished.")
end)
#just sleep a little bit
function main1()i = 0 while true i += 1 println("start sleeping $i...") for j = 15:-1:1 println("still $j") sleep(1) end println("stopped sleeping ...") end
end
#observe a directory for changes in an interval of 15 seconds
function main2()dir = "/path_to_observed_dir/" i = 0 while true i += 1 println("start observing round $i...") a = watch_file(dir,15) if a.changed println("changed") else println("status quo") end println("... stopped observing") end
end
main1()
#or
#main2()
(where you have to replace
/path_to_error_dir/
/path_to_observed_dir/
with something real)
and interrupt the script with
kill -15 pid_of_process
with main1() I got in 50% of the runs error nr 1
and with main2() almost every time error 2 or 3.
WHAT I’m doing wrong? Or how can I avoid these errors?
Because they interrupt the cleaning in atexit() what is not desireable.
Which more information do you need to advise me?
Any help, hints or confirmation is very welcome.
As always, THX for reading and any helpful feedback.