Simple Python for loop causes Blender to suddenly hog 75% of all ram
Well, one problem I can think of is that you're asking blender to subdivide a mesh  by cutting everything in half 20 times in a row.  That's 2**20 = around 1 million cuts on every edge, meaning a square face would be cut into 1 trillion faces.

If this is really what you want, you can do it in a single step using a single

bpy.ops.mesh.subdivide(number_cuts=1048576)


My suspicion is that this is not really what you want to do.  Mostly because I can't think of any machines that can stash the vertices and face loops for several trillion faces.