Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.datemas.de!weretis.net!feeder4.news.weretis.net!storethat.news.telefonica.de!telefonica.de!news.panservice.it!feed.xsnews.nl!border02.ams.xsnews.nl!feeder04.ams.xsnews.nl!feeder03.ams.xsnews.nl!abp001.ams.xsnews.nl!frontend-F10-19.ams.news.kpn.nl From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Re: l = range(int(1E9)) Organization: Decebal Computing References: <87k2wtvbx1.fsf@Equus.decebal.nl> X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E X-Homepage: http://www.decebal.nl/ Date: Thu, 30 Apr 2015 19:28:28 +0200 Message-ID: <874mnxv83n.fsf@Equus.decebal.nl> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:auTDrLJcMnRBQTrbWEo9sahoKig= MIME-Version: 1.0 Content-Type: text/plain Lines: 27 NNTP-Posting-Host: 81.207.62.244 X-Trace: 1430415892 news.kpn.nl 21101 81.207.62.244@kpn/81.207.62.244:40052 Xref: csiph.com comp.lang.python:89653 Op Thursday 30 Apr 2015 18:55 CEST schreef Jon Ribbens: > On 2015-04-30, Cecil Westerhof wrote: >> If I execute: >> l = range(int(1E9) >> >> The python process gobbles up all the memory and is killed. The >> problem is that after this my swap is completely used, because >> other processes have swapped to it. This make those programs more >> slowly. Is there a way to circumvent Python claiming all the >> memory? >> >> By the way: this is CPython 2.7.8. > > It's your operating system's job to handle processes. > > If you use xrange() instead of range() then you will get an iterator > which will return each of the numbers in turn without any need to > create an enormous list of all of them. I did it on purpose. Wanted to now the limits. Just need to use ulimit to get a MemoryError. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof