Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.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.066 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'callback': 0.09; 'method,': 0.09; 'cc:addr:python-list': 0.11; 'broken.': 0.16; 'closure,': 0.16; 'expect,': 0.16; 'unlikely': 0.16; 'wrappers': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'cc:2**0': 0.24; 'references': 0.26; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; 'message- id:@mail.gmail.com': 0.30; 'fri,': 0.33; 'not.': 0.33; 'no,': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'method': 0.36; 'pm,': 0.38; 'expect': 0.39; 'to:addr:gmail.com': 0.65; 'hang': 0.67; '20,': 0.68; 'fact,': 0.69; 'subject:Design': 0.78; '2015': 0.84; 'subject:thought': 0.84; 'instantly.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=ltaIKPQn4pObs2k6fTlaAT6yL3IPYNUtptdZviNnSUg=; b=FPDgwqv3K5i+oyR35SFSi4IKvLcPxiUE64cN5mG25FF6ykGYTjaUCyBaTq1/1LzcWc 2ZZfeEv/sN2aICzNn9phnQwqSqsdqeyxHG8gofYFRb30iIcU6cODbh4okzJqWaqS3DOu Ugz2l4hYvX0dS9bRQDr7S0Jn8rE3jZ8Z1jRD1FFLj9DaGaytTM/esvjoDZnyStHfI+p9 5tS9mueVGrTdU8zf7/6w7pTOLRLuyQN2SvDKftj97Ou0e7sZv1XwfWvva/qmyvxaxoM8 yO0/6yMvi71/Op8wPzlAdOJvxghb7FV5T/hbF3VvEnRjrOFGV3HGMmWMCEzmghDlXQbz I4dw== X-Received: by 10.140.148.4 with SMTP id 4mr6013852qhu.61.1424528716384; Sat, 21 Feb 2015 06:25:16 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> From: Devin Jeanpierre Date: Sat, 21 Feb 2015 06:24:36 -0800 Subject: Re: Design thought for callbacks To: Chris Angelico Content-Type: text/plain; charset=UTF-8 Cc: "comp.lang.python" 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: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424528721 news.xs4all.nl 2868 [2001:888:2000:d::a6]:60247 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3707 X-Received-Body-CRC: 329469865 Xref: csiph.com comp.lang.python:86038 On Fri, Feb 20, 2015 at 9:42 PM, Chris Angelico wrote: > No, it's not. I would advise using strong references - if the callback > is a closure, for instance, you need to hang onto it, because there > are unlikely to be any other references to it. If I register a > callback with you, I expect it to be called; I expect, in fact, that > that *will* keep my object alive. For that matter, if the callback is a method, you need to hang onto it, because method wrappers are generated on demand, so the method would be removed from the valid callbacks instantly. Weak references for callbacks are broken. -- Devin