[Tutor] job killed: too high numbers?
Peter Otten
__peter__ at web.de
Tue Sep 20 12:55:41 EDT 2016
Gabriele Brambilla wrote:
> Hi,
>
> I have this script
> points = 33750000000
> for iw in range(points):
> print iw
>
>
> But when I run it it is killed in the for cycle, it doesn't print any
> number:
>
> [gabriele:~/Desktop/GITcode] gbrambil% python EknotFromKostas.py
> im here
> ../NOBACKUP/heavi3/EX_104189.dat
> pastopens
> Killed
>
> does it mean that my number of points is too high?
In Python 2 range(points) creates a list. To store only the object
references in the list (the actual int object takes much more memory) you
need
>>> 33750000000 * 8
270000000000
Bytes or
>>> _ / 2**30
251.4570951461792
i. e. over 250 GiB of RAM on a 64 bit system.
While you can replace range() with xrange() in Python 2 or switch to Python
3 where range() is an object
>>> range(33750000000)
range(0, 33750000000)
you should start with much smaller numbers and then extrapolate the expected
runtime and memory consumption of your script once it does anything useful.
More information about the Tutor
mailing list