-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathfinalize_test_script.jl
48 lines (45 loc) · 1.07 KB
/
finalize_test_script.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using PythonCall
# This would consistently segfault pre-GC-thread-safety
function test()
pyobjs = map(pyint, 1:10)
Threads.@threads for i = 1:10
finalize(pyobjs[i])
end
# The following loop is a workaround and can be removed if the issue is fixed:
# https://github.com/JuliaLang/julia/issues/40626#issuecomment-1054890774
Threads.@threads :static for _ = 1:Threads.nthreads()
Timer(Returns(nothing), 0; interval = 1)
end
nothing
end
function decrefs()
n = PythonCall.Core.NUM_DECREFS[]
PythonCall.Core.NUM_DECREFS[] = 0
n
end
GC.gc()
decrefs()
println("test()")
test()
println(" decrefs: ", decrefs())
println("gc(false)")
GC.gc(false)
println(" decrefs: ", decrefs())
println("gc(false)")
GC.gc(false)
println(" decrefs: ", decrefs())
println("gc()")
GC.gc()
println(" decrefs: ", decrefs())
println("gc()")
GC.gc()
println(" decrefs: ", decrefs())
println("gc()")
GC.gc()
println(" decrefs: ", decrefs())
println("gc()")
GC.gc()
println(" decrefs: ", decrefs())
println("gc()")
GC.gc()
println(" decrefs: ", decrefs())