@@ -813,6 +813,14 @@ macro sync_add(expr)
813813 end
814814end
815815
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+
816824# runtime system hook called when a task finishes
817825function task_done_hook (t:: Task )
818826 # `finish_task` sets `sigatomic` before entering this function
@@ -834,10 +842,8 @@ function task_done_hook(t::Task)
834842 end
835843
836844 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)
841847 end
842848 end
843849 # Clear sigatomic before waiting
@@ -848,11 +854,8 @@ function task_done_hook(t::Task)
848854 # If an InterruptException happens while blocked in the event loop, try handing
849855 # the exception to the REPL task since the current task is done.
850856 # 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)
856859 else
857860 rethrow ()
858861 end
0 commit comments