Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for profile peek task to stop before exit #51409

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ if is_primary_base_module
# triggers printing the report and (optionally) saving a heap snapshot after a SIGINFO/SIGUSR1 profile request
# Needs to be in Base because Profile is no longer loaded on boot
const PROFILE_PRINT_COND = Ref{Base.AsyncCondition}()
global profile_peek_task::Task
function profile_printing_listener()
profile = nothing
try
Expand Down Expand Up @@ -607,7 +608,8 @@ function __init__()
Base.uv_unref(cond.handle)
PROFILE_PRINT_COND[] = cond
ccall(:jl_set_peek_cond, Cvoid, (Ptr{Cvoid},), PROFILE_PRINT_COND[].handle)
errormonitor(Threads.@spawn(profile_printing_listener()))
global profile_peek_task = Threads.@spawn(profile_printing_listener())
errormonitor(profile_peek_task)
end
_require_world_age[] = get_world_counter()
# Prevent spawned Julia process from getting stuck waiting on Tracy to connect.
Expand Down
15 changes: 14 additions & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@ Stop the program with an exit code. The default exit code is zero, indicating th
program completed successfully. In an interactive session, `exit()` can be called with
the keyboard shortcut `^D`.
"""
exit(n) = ccall(:jl_exit, Cvoid, (Int32,), n)
function exit(n)
if generating_output()
# wait for any known tasks that might be slow to stop and cause spurious warnings during
# precompilation
wait_for_known_tasks()
end
return ccall(:jl_exit, Cvoid, (Int32,), n)
end
exit() = exit(0)


function wait_for_known_tasks()
isdefined(Base, profile_peek_task) && _wait(profile_peek_task)
return nothing
end

const roottask = current_task()

is_interactive = false
Expand Down