tiny script has memory leak

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Thu May 17 05:50:28 EDT 2012


gry <georgeryoung at gmail.com> writes:

> sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2
> [gcc-4_3-branch revision 141291]]

> I thought this script would be very lean and fast, but with a large
> value for n (like 150000), it uses 26G of virtural memory, and things
> start to crumble.
>
> #!/usr/bin/env python
> '''write a file of random integers.  args are: file-name how-many'''
> import sys, random
>
> f = open(sys.argv[1], 'w')
> n = int(sys.argv[2])
> for i in xrange(n):
>     print >>f, random.randint(0, sys.maxint)
> f.close()

sys.version is '2.6.6 (r266:84292, Sep 15 2010, 16:22:56) \n[GCC 4.4.5]'
here, and your script works like a charm. BTW, I would use f.write()
instead of print >> f (which I think is deprecated).

-- Alain.



More information about the Python-list mailing list