Try subdividing a plane 20 times manually by successively hitting W ->Subdivide. You won't get past iteration 9 (or 10, 11.. maybe 12) before your machine starts to break out in a sweat. This isn't so much a Python problem as misunderstanding about what subdivide does.
The default single cut per subdivide turns each face into 4 faces. here a short snippet to print out the numbers involved.
prev = [1]
for i in range(20):
last = prev[-1] * 4
print(i+1, prev[-1], '->', last)
prev.append(last)
outputs (here ->
means subdivide):
1 1 -> 4
2 4 -> 16
3 16 -> 64
4 64 -> 256
5 256 -> 1024
6 1024 -> 4096
7 4096 -> 16384
8 16384 -> 65536
9 65536 -> 262144
10 262144 -> 1048576
11 1048576 -> 4194304
12 4194304 -> 16777216
13 16777216 -> 67108864
14 67108864 -> 268435456
15 268435456 -> 1073741824
16 1073741824 -> 4294967296
17 4294967296 -> 17179869184
18 17179869184 -> 68719476736
19 68719476736 -> 274877906944
20 274877906944 -> 1099511627776
after 20 iterations you would have 1 099 511 627 776 faces.