Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 135627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:49:13+00:00 2026-05-11T06:49:13+00:00

I have a project where i’m trying to use weakrefs with callbacks, and I

  • 0

I have a project where i’m trying to use weakrefs with callbacks, and I don’t understand what I’m doing wrong. I have created simplified test that shows the exact behavior i’m confused with.

Why is it that in this test test_a works as expected, but the weakref for self.MyCallbackB disappears between the class initialization and calling test_b? I thought like as long as the instance (a) exists, the reference to self.MyCallbackB should exist, but it doesn’t.

import weakref  class A(object):     def __init__(self):          def MyCallbackA():             print 'MyCallbackA'         self.MyCallbackA = MyCallbackA          self._testA = weakref.proxy(self.MyCallbackA)         self._testB = weakref.proxy(self.MyCallbackB)      def MyCallbackB(self):         print 'MyCallbackB'      def test_a(self):         self._testA()      def test_b(self):         self._testB()  if __name__ == '__main__':     a = A()         a.test_a()     a.test_b() 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:49:14+00:00Added an answer on May 11, 2026 at 6:49 am

    You want a WeakMethod.

    An explanation why your solution doesn’t work can be found in the discussion of the recipe:

    Normal weakref.refs to bound methods don’t quite work the way one expects, because bound methods are first-class objects; weakrefs to bound methods are dead-on-arrival unless some other strong reference to the same bound method exists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have project that I'm working on that is going to require a webserver.
I have a project that I'm currently working on but it currently only supports
I have a project that I would like to start beta testing soon, it
I have a project the requires the use of the exec family. My project
I have a project where a .master page was created without a code behind
I have project X, fully operational that compiles into X.exe I have project Y,
i have project in .net , i want to test it. But i dont
I have project with my resources (resx files), and I want to use them
I have project created in eclipse. Can you please guide me how can i
Have a project compiled to use (TargetFrameworkVersion) framework version 3.0 however it looks like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.