Base.register_taskdone_hook crashes julia

Am I using it correctly? This simple hook crashes julia in both 0.6 and 0.7.

julia> slow(n) = (sleep(n); rand())
slow (generic function with 1 method)

julia> t = @async slow(15)
Task (runnable) @0x0000000112d3bcd0

julia> Base.register_taskdone_hook(t, (tsk) -> println("good"))
Task (runnable) @0x0000000112d3bcd0

julia> goodfatal: error thrown and no exception handler available.
ErrorException("schedule: Task not runnable")
rec_backtrace at /Users/osx/buildbot/slave/package_osx64/build/src/stackwalk.c:84
record_backtrace at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:245 [inlined]
jl_throw at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:564
enq_work at ./event.jl:82
uv_writecb_task at ./stream.jl:884
jlcapi_uv_writecb_task_23794 at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
uv__write_callbacks at /Users/osx/buildbot/slave/package_osx64/build/deps/srccache/libuv-d8ab1c6a33e77bf155facb54215dd8798e13825d/src/unix/stream.c:967
uv__stream_io at /Users/osx/buildbot/slave/package_osx64/build/deps/srccache/libuv-d8ab1c6a33e77bf155facb54215dd8798e13825d/src/unix/stream.c:1317
uv__run_pending at /Users/osx/buildbot/slave/package_osx64/build/deps/srccache/libuv-d8ab1c6a33e77bf155facb54215dd8798e13825d/src/unix/core.c:765
uv_run at /Users/osx/buildbot/slave/package_osx64/build/deps/srccache/libuv-d8ab1c6a33e77bf155facb54215dd8798e13825d/src/unix/core.c:346
process_events at ./libuv.jl:82 [inlined]
wait at ./event.jl:216
uv_write at ./stream.jl:811
unsafe_write at ./stream.jl:832
print at ./strings/io.jl:122
jlcall_print_21039 at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
print at ./strings/io.jl:40
#5 at ./REPL[3]:1
unknown function (ip: 0x1200bf042)
foreach at ./abstractarray.jl:1733
unknown function (ip: 0x1200beef6)
task_done_hook at ./task.jl:217
jlcall_task_done_hook_21957 at /Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/osx/buildbot/slave/package_osx64/build/src/./julia.h:1424 [inlined]
finish_task at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:232
start_task at /Users/osx/buildbot/slave/package_osx64/build/src/task.c:275

Looks like the println statement crashes it. If I do other things then it’s fine. Still, I would rather not see it crash :slight_smile:

A working example:

julia> cnt = 1
1

julia> slow(n) = (sleep(n); rand())
slow (generic function with 1 method)

julia> t = @async slow(15)
Task (runnable) @0x000000010ef37cd0

julia> Base.register_taskdone_hook(t, (tsk) -> (global cnt; cnt += 1))
Task (runnable) @0x000000010ef37cd0

julia> cnt
1

julia> cnt
2