Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90873

Re: Why does the first loop go wrong with Python3

Path csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.033
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'explicitly': 0.05; 'function,': 0.09; 'subject:Python3': 0.09; 'subject:Why': 0.09; 'cc:addr:python-list': 0.11; 'alert': 0.16; 'alert,': 0.16; 'cleaned': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'garbage': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'normally': 0.19; 'work,': 0.20; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'instance,': 0.24; 'cc:2**0': 0.24; 'references': 0.26; 'gets': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'have,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'about.': 0.31; 'invoke': 0.31; "they'll": 0.31; 'probably': 0.32; 'handled': 0.32; 'actual': 0.34; 'subject:the': 0.34; 'subject:with': 0.35; 'something': 0.35; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'curious': 0.36; 'returning': 0.36; 'done': 0.36; 'being': 0.38; 'audio': 0.38; 'depends': 0.38; 'whatever': 0.38; 'anything': 0.39; 'called': 0.40; 'is.': 0.60; 'then,': 0.60; 'simply': 0.61; "you're": 0.61; "you'll": 0.62; 'real': 0.63; 'finish': 0.65; '20,': 0.68; 'hour': 0.70; '2015': 0.84; 'guarantee.': 0.84; 'guaranteed.': 0.84; 'promptly.': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=1adTPVi0hRoGmx9t4kgcq7LvnanH/NAAQ2TFPRSNHiE=; b=BST6FD7uuInQHMEYVXMkf8U66agMcEFhZRE4wBzpmrCyBe/anZo5E9zwyaVQgY5Fdb IkQ/VBtustlmI2n0XrFWsmtZznGPquRfAi/c+MiPHB8lxYdklTwpmKv3+oDrRRkz+UIj 1xZakPGsy47uKa30+dQxCPm/4bCqAaZytflTF3YYYaBRkHidSNxYcvE5k/TThkpoS1dD owwegRMlarnI7weuO9cUk7uWHbQ3a6uwOXJ4/1YdCrg2r8zcbIAOUDrGFZ4+IBz8gFkE EVd4K24r74kumkUCDdqLtV6vAwJjJXe0X42gtI5yGxMR0RaSvm7OGRzHCRNWxYhsS2rL Ol6g==
MIME-Version 1.0
X-Received by 10.43.0.67 with SMTP id nl3mr20095681icb.59.1432055510454; Tue, 19 May 2015 10:11:50 -0700 (PDT)
In-Reply-To <87wq04ttbp.fsf@Equus.decebal.nl>
References <878uckvjoy.fsf@Equus.decebal.nl> <mailman.133.1432041396.17265.python-list@python.org> <874mn8vd8n.fsf@Equus.decebal.nl> <mailman.142.1432050607.17265.python-list@python.org> <87wq04ttbp.fsf@Equus.decebal.nl>
Date Wed, 20 May 2015 03:11:50 +1000
Subject Re: Why does the first loop go wrong with Python3
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.145.1432055512.17265.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1432055513 news.xs4all.nl 2845 [2001:888:2000:d::a6]:59442
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90873

Show key headers only | View raw


On Wed, May 20, 2015 at 2:39 AM, Cecil Westerhof <Cecil@decebal.nl> wrote:
> By the way, what also works is:
>     p = None
>
> But it was just a try in ipython3. I would never do this in real code.
> I was just curious if this would be handled correctly and it is. :-)

That _may_ work, but it depends on their not being any other
references to it, and also depends on it being garbage-collected
promptly. Neither is guaranteed. Explicitly wait()ing on it is a
guarantee.

Simply dropping the object is a good way to "probably dispose" of
something that you don't care about. For instance, you asynchronously
invoke VLC to play some audio alert, and the subprocess might finish
before you're done with the current function, or might finish after.
You don't really care about its actual termination, and certainly
don't want to delay anything waiting for it, but you do want to clean
up resources at some point. Dropping the object (keeping no references
to it, returning from the function you called it from, unsetting any
references you have, whatever makes sense) will normally mean that it
gets garbage collected and cleaned up _at some point_, without really
guaranteeing exactly when; for instance, if you have an alert like
this once per hour and watch 'top' for the number of zombies, you'll
probably see some now and then, but they'll never get to apocalyptic
numbers.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Why does the first loop go wrong with Python3 Cecil Westerhof <Cecil@decebal.nl> - 2015-05-19 14:24 +0200
  Re: Why does the first loop go wrong with Python3 Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-19 14:16 +0100
    Re: Why does the first loop go wrong with Python3 Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2015-05-19 16:38 +0200
    Re: Why does the first loop go wrong with Python3 Cecil Westerhof <Cecil@decebal.nl> - 2015-05-19 16:44 +0200
      Re: Why does the first loop go wrong with Python3 Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-19 09:49 -0600
        Re: Why does the first loop go wrong with Python3 Cecil Westerhof <Cecil@decebal.nl> - 2015-05-19 18:39 +0200
          Re: Why does the first loop go wrong with Python3 Chris Angelico <rosuav@gmail.com> - 2015-05-20 03:11 +1000

csiph-web