Use Threads.@spawn instead of the broken hang-prone Distributed.

Thu, 05 Dec 2019 16:50:11 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 05 Dec 2019 16:50:11 +0200
changeset 11
f1bbdf68f35b
parent 10
fdf2f44be973
child 12
5b18eb027b03

Use Threads.@spawn instead of the broken hang-prone Distributed.
Also fix a few related things.

Project.toml file | annotate | diff | comparison | revisions
src/Visualise.jl file | annotate | diff | comparison | revisions
test/denoise.jl file | annotate | diff | comparison | revisions
--- a/Project.toml	Thu Nov 21 22:17:52 2019 -0500
+++ b/Project.toml	Thu Dec 05 16:50:11 2019 +0200
@@ -5,7 +5,6 @@
 
 [deps]
 AlgTools = "c46e2e78-5339-41fd-a966-983ff60ab8e7"
-Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
 FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
 Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
 Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
--- a/src/Visualise.jl	Thu Nov 21 22:17:52 2019 -0500
+++ b/src/Visualise.jl	Thu Dec 05 16:50:11 2019 +0200
@@ -5,7 +5,6 @@
 module Visualise
 
 using Printf
-using Distributed
 using FileIO
 using Setfield
 using Images, Plots, Measures
@@ -39,8 +38,8 @@
 end
 
 struct State
-    vis :: Union{Distributed.RemoteChannel,Bool,Nothing}
-    visproc :: Union{Nothing,Future}
+    vis :: Union{Channel,Bool,Nothing}
+    visproc :: Union{Nothing,Task}
     start_time :: Union{Real,Nothing}
     wasted_time :: Real
     log :: LinkedList{LogEntry}
@@ -82,14 +81,14 @@
     display(plot([plt(imgs[i]) for i =1:length(imgs)]..., reuse=true, margin=0mm))
 end
 
-function visualise(rc_or_vis, imgs)
-    if isa(rc_or_vis, RemoteChannel)
-        rc = rc_or_vis
+function visualise(channel_or_toggle, imgs)
+    if isa(channel_or_toggle, Channel)
+        rc = channel_or_toggle
         while isready(rc)
             take!(rc)
         end
         put!(rc, imgs)
-    elseif isa(rc_or_vis, Bool) && rc_or_vis
+    elseif isa(channel_or_toggle, Bool) && channel_or_toggle
         do_visualise(imgs)
     end
 end
@@ -164,8 +163,8 @@
 function initialise_visualisation(visualise; iterator=iterate_visualise)
     # Create visualisation
     if visualise
-        rc = RemoteChannel()
-        visproc = @spawn bg_visualise(rc)
+        rc = Channel()
+        visproc = Threads.@spawn bg_visualise(rc)
         vis =rc
         #vis = true
 
@@ -182,9 +181,9 @@
 end
 
 function finalise_visualisation(st)
-    if isa(st.rc, RemoteChannel)
+    if isa(st.vis, Channel)
         # Tell subprocess to finish, and wait
-        put!(st.rc, nothing)
+        put!(st.vis, nothing)
         wait(st.visproc)
     end
 end
--- a/test/denoise.jl	Thu Nov 21 22:17:52 2019 -0500
+++ b/test/denoise.jl	Thu Dec 05 16:50:11 2019 +0200
@@ -60,5 +60,5 @@
     end
 
     # Exit background visualiser
-    finish_visualisation(st)
+    finalise_visualisation(st)
 end

mercurial