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)
78
78
@task_executor = Options . executor_from_options ( opts ) || Concurrent . global_io_executor
79
79
@timer_executor = SingleThreadExecutor . new
80
80
@condition = Event . new
81
+ @ruby_pid = $$ # detects if Ruby has forked
81
82
self . auto_terminate = opts . fetch ( :auto_terminate , true )
82
83
end
83
84
@@ -95,6 +96,7 @@ def post_task(task)
95
96
# @!visibility private
96
97
def ns_post_task ( task )
97
98
return false unless ns_running?
99
+ ns_reset_if_forked
98
100
if ( task . initial_delay ) <= 0.01
99
101
task . executor . post { task . process_task }
100
102
else
@@ -121,11 +123,20 @@ def remove_task(task)
121
123
#
122
124
# @!visibility private
123
125
def ns_shutdown_execution
126
+ ns_reset_if_forked
124
127
@queue . clear
125
128
@timer_executor . kill
126
129
stopped_event . set
127
130
end
128
131
132
+ def ns_reset_if_forked
133
+ if $$ != @ruby_pid
134
+ @queue . clear
135
+ @condition . reset
136
+ @ruby_pid = $$
137
+ end
138
+ end
139
+
129
140
# Run a loop and execute tasks in the scheduled order and at the approximate
130
141
# scheduled time. If no tasks remain the thread will exit gracefully so that
131
142
# 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