You can check what happens without risking filling up all available memory. You can set the memory limit explicitly :
#!/usr/bin/env python import contextlib import resource @contextlib.contextmanager def limit(limit, type=resource.RLIMIT_AS): soft_limit, hard_limit = resource.getrlimit(type) resource.setrlimit(type, (limit, hard_limit))
This code consumes 100% of the processor (on a single core), and memory consumption is growing very slowly.
Basically, you should get a MemoryError at some point, if that happens before your computer turns to dust, it's unclear. CPython uses a continuous block of memory to store numbers , and therefore you may get an error even if there is RAM but is fragmented.
Your specific code should not run it, but overall you can also get an OverflowError if you try to build an integer larger than sys.maxsize bytes .
source share