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


Groups > comp.lang.python > #86121

Re: Design thought for callbacks

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cfkaran2@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'laura': 0.07; 'see:': 0.07; '22,': 0.09; 'callback': 0.09; 'creighton': 0.09; 'indeed,': 0.09; "people's": 0.09; 'cc:addr:python-list': 0.11; 'mostly': 0.14; 'blocking': 0.16; 'magic': 0.16; 'registered.': 0.16; 'surprising': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'library': 0.18; 'mechanism': 0.19; 'possible,': 0.19; 'slightly': 0.19; 'fit': 0.20; 'feb': 0.22; 'appears': 0.22; 'code,': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'case.': 0.24; "haven't": 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'bigger': 0.30; 'especially': 0.30; "i'm": 0.30; 'code': 0.31; 'that.': 0.31; 'about.': 0.31; 'away.': 0.31; 'releasing': 0.31; 'writes:': 0.31; 'figure': 0.32; 'run': 0.32; 'programmers': 0.33; 'problem': 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'library.': 0.36; 'charset:us-ascii': 0.36; "i'll": 0.36; 'being': 0.38; 'message- id:@gmail.com': 0.38; 'needed': 0.38; 'track': 0.38; 'rather': 0.38; 'little': 0.38; 'users': 0.40; 'even': 0.60; 'solve': 0.60; 'hope': 0.61; 'gone': 0.61; "you're": 0.61; 'first': 0.61; 'making': 0.63; 'header:Message-Id:1': 0.63; 'more': 0.64; 'situation': 0.65; 'bottom': 0.67; 'design.': 0.68; 'goal': 0.75; 'hoping': 0.75; 'subject:Design': 0.78; '2015': 0.84; 'subject:thought': 0.84; 'forgotten': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ziko0uj7nbIEpaDgC2zWDgXyjsN4xrdWYOQfsXxLSJ0=; b=SoAXnrxj3ycxLcuFWheQYSzyKkaIAafnweyibWn9pHMJckitEocPWCv7y+jpG/xMdx sB10fQ0U+q7MEVGydJTv2tXoPZnjBp3kxRild4Yfayo6iCM+aZx9mxBBZ7HKTG74tIHz dWrvIyOOCNSmpyupfcefDFvXzW567ZU0aNzZTWta3ydr/AoucpOlGnujyQ5ksVL9Qal2 ex8zWTe7/qbHm2EAPXct+Nkuwt0s08wEGBzUjOWRO/wnHMkvCqkib0Iz8u5z5L70cg0I mTJEMi4NCz///M3ZVuY2ZUCoHu0+cpoL6BtJhqoKjN0OFEbAVlBJkQT17wPnN3kXADaB ORLA==
X-Received by 10.52.25.11 with SMTP id y11mr6386977vdf.51.1424614223133; Sun, 22 Feb 2015 06:10:23 -0800 (PST)
Content-Type text/plain; charset=us-ascii
Mime-Version 1.0 (Mac OS X Mail 6.6 \(1510\))
Subject Re: Design thought for callbacks
From Cem Karan <cfkaran2@gmail.com>
In-Reply-To <201502221252.t1MCq11A012613@fido.openend.se>
Date Sun, 22 Feb 2015 09:10:20 -0500
Content-Transfer-Encoding quoted-printable
References <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <mailman.18947.1424497301.18130.python-list@python.org> <54e8af1b$0$12976$c3e8da3$5496439d@news.astraweb.com> <87egpjtcp0.fsf@elektro.pacujo.net><5204A93E-8834-4C6E-9B6C-F885A4B3D89A@gmail.com> <201502221252.t1MCq11A012613@fido.openend.se>
To Laura Creighton <lac@openend.se>
X-Mailer Apple Mail (2.1510)
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.19013.1424614226.18130.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424614226 news.xs4all.nl 2905 [2001:888:2000:d::a6]:48991
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86121

Show key headers only | View raw


On Feb 22, 2015, at 7:52 AM, Laura Creighton <lac@openend.se> wrote:

> In a message of Sun, 22 Feb 2015 07:16:14 -0500, Cem Karan writes:
> 
>> This was PRECISELY the situation I was thinking about.  My hope was
>> to make the callback mechanism slightly less surprising by allowing
>> the user to track them, releasing them when they aren't needed
>> without having to figure out where the callbacks were registered.
>> However, it appears I'm making things more surprising rather than
>> less.
> 
> You may be able to accomplish your goal by using a Queue with a
> producer/consumer model.
> see: http://stackoverflow.com/questions/9968592/turn-functions-with-a-callback-into-python-generators
> 
> especially the bottom of that.
> 
> I haven't run the code, but it looks mostly reasonable, except that
> you do not want to rely on the Queue maxsize being 1 here, and
> indeed, I almost always want a bigger Queue  in any case.  Use
> Queue.task_done if blocking the producer features in your design.
> 
> The problem that you are up against is that callbacks are inherantly
> confusing, even to programmers who are learning about them for the
> first time.  They don't fit people's internal model of 'how code works'.
> There isn't a whole lot one can do about that except to
> try to make the magic do as little as possible, so that more of the
> code works 'the way people expect'.

I think what you're suggesting is that library users register a Queue instead of a callback, correct?  The problem is that I'll then have a strong reference to the Queue, which means I'll be pumping events into it after the user code has gone away.  I was hoping to solve the problem of forgotten registrations in the library.

Thanks,
Cem Karan

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


Thread

Re: Design thought for callbacks "Frank Millman" <frank@chagford.com> - 2015-02-21 07:41 +0200
  Re: Design thought for callbacks Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-22 03:15 +1100
    Re: Design thought for callbacks Marko Rauhamaa <marko@pacujo.net> - 2015-02-21 19:08 +0200
      Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 07:16 -0500
        Re: Design thought for callbacks Marko Rauhamaa <marko@pacujo.net> - 2015-02-22 14:46 +0200
          Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 09:17 -0500
      Re: Design thought for callbacks Laura Creighton <lac@openend.se> - 2015-02-22 13:52 +0100
      Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 09:10 -0500
    Re: Design thought for callbacks "Frank Millman" <frank@chagford.com> - 2015-02-22 08:44 +0200
      Re: Design thought for callbacks Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-02-22 23:15 +1300
        Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 09:22 -0500
          Re: Design thought for callbacks Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-02-24 18:45 +1300
            Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-24 06:06 -0500
        Re: Design thought for callbacks Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-22 23:57 -0700

csiph-web