File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ def ns_initialize(opts)
7878 @task_executor = Options . executor_from_options ( opts ) || Concurrent . global_io_executor
7979 @timer_executor = SingleThreadExecutor . new
8080 @condition = Event . new
81+ @ruby_pid = $$ # detects if Ruby has forked
8182 self . auto_terminate = opts . fetch ( :auto_terminate , true )
8283 end
8384
@@ -95,6 +96,7 @@ def post_task(task)
9596 # @!visibility private
9697 def ns_post_task ( task )
9798 return false unless ns_running?
99+ ns_reset_if_forked
98100 if ( task . initial_delay ) <= 0.01
99101 task . executor . post { task . process_task }
100102 else
@@ -121,11 +123,20 @@ def remove_task(task)
121123 #
122124 # @!visibility private
123125 def ns_shutdown_execution
126+ ns_reset_if_forked
124127 @queue . clear
125128 @timer_executor . kill
126129 stopped_event . set
127130 end
128131
132+ def ns_reset_if_forked
133+ if $$ != @ruby_pid
134+ @queue . clear
135+ @condition . reset
136+ @ruby_pid = $$
137+ end
138+ end
139+
129140 # Run a loop and execute tasks in the scheduled order and at the approximate
130141 # scheduled time. If no tasks remain the thread will exit gracefully so that
131142 # garbage collection can occur. If there are no ready tasks it will sleep
You can’t perform that action at this time.
0 commit comments