File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -632,7 +632,18 @@ function interrupt(w::InProcessWorker)
632
632
nothing
633
633
end
634
634
635
+ """
636
+ Malt.requestgc(w::Worker)
635
637
638
+ Request a garbage collection on the worker `w`. This is a non-blocking call (on the worker).
639
+ """
640
+ function requestgc (w:: Worker )
641
+ if ! isrunning (w)
642
+ @warn " Tried to gc a worker that has already shut down." summary (w)
643
+ else
644
+ remote_eval_wait (Main, worker, :(Base. notify (Main. _gc_event)))
645
+ end
646
+ end
636
647
637
648
638
649
# Based on `Base.task_done_hook`
Original file line number Diff line number Diff line change @@ -161,6 +161,17 @@ format_error(err, bt) = sprint() do io
161
161
end
162
162
163
163
const _channel_cache = Dict {UInt64, AbstractChannel} ()
164
+ const _gc_event = Threads. Event (true )
165
+
166
+ const _gc_task = Threads. @spawn :default begin
167
+ for _i in Iterators. countfrom (1 )
168
+ wait (_gc_event)
169
+ sleep (5 ) # debounce 5 seconds
170
+ GC. gc (true )
171
+ # ignore all events after the gc
172
+ @atomic _gc_event. set = false
173
+ end
174
+ end
164
175
165
176
if abspath (PROGRAM_FILE ) == @__FILE__
166
177
main ()
You can’t perform that action at this time.
0 commit comments