File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,15 @@ function setup_onfixedthread()
40
40
worker_task = Task () do
41
41
while true
42
42
f = take! (channel_input)
43
- put! (channel_output, f ())
43
+ ret = try
44
+ Some (invokelatest (f))
45
+ # invokelatest is necessary for development and interactive use.
46
+ # Otherwise, only a method f defined in a world prior to the call of
47
+ # launch_worker would work.
48
+ catch e
49
+ e, catch_backtrace ()
50
+ end
51
+ put! (channel_output, ret)
44
52
end
45
53
end
46
54
# code adapted from set_task_tid! in StableTasks.jl, itself taken from Dagger.jl
@@ -63,7 +71,17 @@ function setup_onfixedthread()
63
71
end
64
72
function onfixedthread (f)
65
73
put! (channel_input, f)
66
- take! (channel_output)
74
+ ret = take! (channel_output)
75
+ if ret isa Tuple
76
+ e, backtrace = ret
77
+ printstyled (stderr , " ERROR: " ; color= :red , bold= true )
78
+ showerror (stderr , e)
79
+ Base. show_backtrace (stderr , backtrace)
80
+ println (stderr )
81
+ throw (e) # the stacktrace of the actual error is printed above
82
+ else
83
+ something (ret)
84
+ end
67
85
end
68
86
launch_worker, onfixedthread
69
87
end
Original file line number Diff line number Diff line change 836
836
prop_task = fetch (task)
837
837
@test properties == prop_task
838
838
end
839
+
840
+ @testitem " on_main_thread" begin
841
+ task = Threads. @spawn PythonCall. C. on_main_thread () do ; Threads. threadid (); end
842
+ @test fetch (task) == 1
843
+ @test_throws DivideError redirect_stderr (devnull ) do
844
+ PythonCall. C. on_main_thread () do
845
+ throw (DivideError ())
846
+ end
847
+ end
848
+ end
You can’t perform that action at this time.
0 commit comments