@@ -813,6 +813,14 @@ macro sync_add(expr)
813
813
end
814
814
end
815
815
816
+ throwto_repl_task (@nospecialize val) = throwto (getfield (active_repl_backend, :backend_task ):: Task , val)
817
+
818
+ function is_repl_running ()
819
+ return isdefined (Base, :active_repl_backend ) &&
820
+ (getfield (active_repl_backend, :backend_task ):: Task ). _state === task_state_runnable &&
821
+ getfield (active_repl_backend, :in_eval )
822
+ end
823
+
816
824
# runtime system hook called when a task finishes
817
825
function task_done_hook (t:: Task )
818
826
# `finish_task` sets `sigatomic` before entering this function
@@ -834,10 +842,8 @@ function task_done_hook(t::Task)
834
842
end
835
843
836
844
if err && ! handled && Threads. threadid () == 1
837
- if isa (result, InterruptException) && active_repl_backend != = nothing &&
838
- active_repl_backend. backend_task. _state === task_state_runnable && isempty (Workqueue) &&
839
- active_repl_backend. in_eval
840
- throwto (active_repl_backend. backend_task, result) # this terminates the task
845
+ if isa (result, InterruptException) && isempty (Workqueue) && is_repl_running ()
846
+ throwto_repl_task (result)
841
847
end
842
848
end
843
849
# Clear sigatomic before waiting
@@ -848,11 +854,8 @@ function task_done_hook(t::Task)
848
854
# If an InterruptException happens while blocked in the event loop, try handing
849
855
# the exception to the REPL task since the current task is done.
850
856
# issue #19467
851
- if Threads. threadid () == 1 &&
852
- isa (e, InterruptException) && active_repl_backend != = nothing &&
853
- active_repl_backend. backend_task. _state === task_state_runnable && isempty (Workqueue) &&
854
- active_repl_backend. in_eval
855
- throwto (active_repl_backend. backend_task, e)
857
+ if Threads. threadid () == 1 && isa (e, InterruptException) && isempty (Workqueue) && is_repl_running ()
858
+ throwto_repl_task (e)
856
859
else
857
860
rethrow ()
858
861
end
0 commit comments