Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'problem:': 0.07; 'default.': 0.09; 'enormous': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; "system's": 0.09; 'way:': 0.09; 'python': 0.11; 'callable': 0.16; 'circumvent': 0.16; 'finney': 0.16; 'iterator': 0.16; 'processes.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'written': 0.21; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'handling': 0.26; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'claiming': 0.31; 'writes:': 0.31; 'device': 0.34; 'case,': 0.35; 'there': 0.35; '8bit%:17': 0.36; 'surely': 0.36; 'doing': 0.36; 'operating': 0.37; 'turn': 0.37; 'list': 0.37; 'ben': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'numbers': 0.61; 'kind': 0.63; 'skip:\xe2 10': 0.65; 'received:125': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: l = range(int(1E9)) Date: Fri, 01 May 2015 03:20:10 +1000 References: <87k2wtvbx1.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:3h7t+3oykP5cpBg5KXysOeJSL80= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430414427 news.xs4all.nl 2901 [2001:888:2000:d::a6]:55807 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89648 Jon Ribbens writes: > 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. […] Is > > there a way to circumvent Python claiming all the memory? You seem to be asking for a way to stop a program doing exactly what it's written to do. I don't know what kind of answer you expect. > It's your operating system's job to handle processes. Indeed. In this case, the program is written to gobble up memory, and the operating system kills it. To “circumvent” that behaviour surely reveals the problem: that the operating system isn't handling processes very well. > > By the way: this is CPython 2.7.8. > > 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. If you use Python 3 instead of the obsolescent Python 2, the ‘range’ callable has this sensible behaviour by default. -- \ “Corporation, n. An ingenious device for obtaining individual | `\ profit without individual responsibility.” —Ambrose Bierce, | _o__) _The Devil's Dictionary_, 1906 | Ben Finney