Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.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.025 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'socket': 0.07; '22,': 0.09; 'callback': 0.09; 'happen,': 0.09; 'name?': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; 'assume': 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'it".': 0.16; 'it;': 0.16; 'none.': 0.16; 'scope,': 0.16; 'steps,': 0.16; 'weird': 0.16; 'wrote:': 0.18; 'normally': 0.19; 'seems': 0.21; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'of.': 0.24; 'connected': 0.24; 'cc:2**0': 0.24; 'holds': 0.26; 'references': 0.26; 'somewhere': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'mode': 0.30; 'message- id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'though.': 0.31; 'file': 0.32; 'this.': 0.32; '"the': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'object,': 0.36; 'done': 0.36; 'should': 0.36; 'skip:o 20': 0.38; 'configured': 0.38; 'whatever': 0.38; 'fact': 0.38; 'pm,': 0.38; 'delete': 0.39; 'skip:u 10': 0.60; "you're": 0.61; "you'll": 0.62; 'name': 0.63; 'such': 0.63; 'happen': 0.63; 'kept': 0.65; 'here': 0.66; 'close': 0.67; 'natural': 0.68; 'listening': 0.74; 'subject:Design': 0.78; '2015': 0.84; 'disagreement': 0.84; 'listener': 0.84; 'subject:thought': 0.84; 'edwards': 0.91; '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=z43MYEudFsJ7SHg2y8Vt9bnoTB5YBmbZQdu8rZdcqB8=; b=dhC43nqkg8V6QaT9EV8kmtJz1qnY0vcrftJ192CPMgqn+JubHYyO8Hwc2SA47z1U8e 0d06E1GZgWSCy0sPQOyFFav8hM1lXmz4XulnXsPhiwqutNsqnkOAK3C6UTDE9+9goi6f /u2QidWY1eVJQK693Y5Lqpq+fLdc9eCJ9+9E1tCfGcuEbcpxafdT+WA/I9jWG89uMrd5 qUM5a0lREJvTz5e+DF6zHRZWuVVVNB9/NYVNTiw8RzILxMhZ+EGMVOsURVDPDk0D/3gh yoZWtTo6i5q8e65LitJkNehAlfKwyOnP4mv6WZzYj4M8zZJW79htHb+GA+NrUCMb1ZGR qX7A== MIME-Version: 1.0 X-Received: by 10.50.61.238 with SMTP id t14mr5377400igr.34.1424571099085; Sat, 21 Feb 2015 18:11:39 -0800 (PST) In-Reply-To: <54e9391b$0$13010$c3e8da3$5496439d@news.astraweb.com> References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <87egpjapxv.fsf@elektro.pacujo.net> <54e9391b$0$13010$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 22 Feb 2015 13:11:38 +1100 Subject: Re: Design thought for callbacks From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424571107 news.xs4all.nl 2858 [2001:888:2000:d::a6]:43884 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86075 On Sun, Feb 22, 2015 at 1:04 PM, Steven D'Aprano wrote: > Marko Rauhamaa wrote: > >> Grant Edwards : >> >>> the polite thing to do is to delete references to it when you're done >>> with it. >> >> I disagree with that recommendation. You should do the natural thing and >> not care who holds references to who. > > I don't understand this. What is "the natural thing" if not to delete > references to an object when you are done with it? Normally you just let > things go out of scope, but if that won't happen, you have to take active > steps, such as calling del or setting the reference to None. I think the disagreement here is over the interpretation of "done with it". If you drop all references to a connected socket object, Python can rightly assume that you're done with the file and want to close it; but what if you drop all references to a listening socket that's been configured to call a function whenever someone connects? def client_connected(sock): sock.send("Hello!\r\n") # whatever listener = socket(23, on_accept=client_connected) What should happen if that main socket isn't bound to a name? In my opinion, the fact that it's configured for callback mode should mean that it's kept alive. But it's also understandable to want to treat it as "done", that it can be disposed of. It seems weird to me that you should have to have a name somewhere that you'll never use, though. ChrisA