This code will stop blender if I will try add someting to kd-tree in for loop. It happens only if you insert at least 2 elements into kd-tree before loop.
Also replacing for loop with manually inserting 3 elements fixes that. Somehow only if the for loop is there the crash happens.
import mathutils
kd = mathutils.kdtree.KDTree(10)
kd.insert((1,1,1), 0)
kd.insert((1,1,2), 1) #remove this line and it will work
kd.balance()
co_find = (1,1,1)
for j in range(3): #or replace this with manually inserting 3 elements and it will work.
kd.insert((4+j+1,4,4), j +2)
kd.balance()
out = kd.find_range(co_find, 4) #script hangs on this line