File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
activesupport/lib/active_support Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
module ActiveSupport
4
4
module ForkTracker # :nodoc:
5
+ module ModernCoreExt
6
+ def _fork
7
+ pid = super
8
+ if pid == 0
9
+ ForkTracker . check!
10
+ end
11
+ pid
12
+ end
13
+ end
14
+
5
15
module CoreExt
6
16
def fork ( ...)
7
17
if block_given?
@@ -28,14 +38,17 @@ module CoreExtPrivate
28
38
29
39
class << self
30
40
def check!
31
- if @pid != Process . pid
41
+ new_pid = Process . pid
42
+ if @pid != new_pid
32
43
@callbacks . each ( &:call )
33
- @pid = Process . pid
44
+ @pid = new_pid
34
45
end
35
46
end
36
47
37
48
def hook!
38
- if Process . respond_to? ( :fork )
49
+ if Process . respond_to? ( :_fork ) # Ruby 3.1+
50
+ ::Process . singleton_class . prepend ( ModernCoreExt )
51
+ elsif Process . respond_to? ( :fork )
39
52
::Object . prepend ( CoreExtPrivate ) if RUBY_VERSION < "3.0"
40
53
::Kernel . prepend ( CoreExtPrivate )
41
54
::Kernel . singleton_class . prepend ( CoreExt )
You can’t perform that action at this time.
0 commit comments