Design thought for callbacks

Fabio Zadrozny fabiofz at gmail.com
Thu Feb 26 19:04:24 EST 2015


On Wed, Feb 25, 2015 at 9:46 AM, Cem Karan <cfkaran2 at gmail.com> wrote:

>
> On Feb 24, 2015, at 8:23 AM, Fabio Zadrozny <fabiofz at gmail.com> wrote:
>
> > Hi Cem,
> >
> > I didn't read the whole long thread, but I thought I'd point you to what
> I'm using in PyVmMonitor (http://www.pyvmmonitor.com/) -- which may
> already cover your use-case.
> >
> > Take a look at the callback.py at
> https://github.com/fabioz/pyvmmonitor-core/blob/master/pyvmmonitor_core/callback.py
> >
> > And its related test (where you can see how to use it):
> https://github.com/fabioz/pyvmmonitor-core/blob/master/_pyvmmonitor_core_tests/test_callback.py
> (note that it falls back to a strong reference on simple functions -- i.e.:
> usually top-level methods or methods created inside a scope -- but
> otherwise uses weak references).
>
> That looks like a better version of what I was thinking about originally.
> However, various people on the list have convinced me to stick with strong
> references everywhere.  I'm working out a possible API right now, once I
> have some code that I can use to illustrate what I'm thinking to everyone,
> I'll post it to the list.
>
> Thank you for showing me your code though, it is clever!
>
> Thanks,
> Cem Karan


​Hi Cem,

Well, I decided to elaborate a bit on the use-case I have and how I use it
(on a higher level):
http://pydev.blogspot.com.br/2015/02/design-for-client-side-applications-in.html

So, you can see if it may be worth for you or not (I agree that sometimes
you should keep strong references, but for my use-cases, weak references
usually work better -- with the only exception being closures, which is
handled different anyways but with the gotcha of having to manually
unregister it).

Best Regards,

Fabio​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150226/2d1d4720/attachment.html>


More information about the Python-list mailing list