getting the reference count of an object ...

  • Thread starter Wildemar Wildenburger
  • Start date
W

Wildemar Wildenburger

.... how?

I'm writing an app that holds a public data dictionary from which other
objects obtain part of their __dict__ values so they all work on the
same dataset (yes I'm fiendishly clever and a constructor of unreadable
sentences (and code) ;)).

My problem is that I haven't found an easy way to determine if said
dictionary contents are still in use (so it is ok to delete them from
the dictionary). I've thought about creating a dict subclass that counts
the number of assignments and deletions but that seems cumbersome (an
bug-prone).

Is there a way to get the reference count of these datadict items? I
imagine that this would be a more stable implementation of such a feature.

Hope this gets my problem accross; if not just bash me and I'll
reformulate. I'm not the best of explainers.

Oh, and sorry if the solution to my problem is obvious (such as an
__refcount__ attribute or some stupid oversight like that).

c.u.
wildemar
 
J

Just

Wildemar Wildenburger said:
... how?

I'm writing an app that holds a public data dictionary from which other
objects obtain part of their __dict__ values so they all work on the
same dataset (yes I'm fiendishly clever and a constructor of unreadable
sentences (and code) ;)).

My problem is that I haven't found an easy way to determine if said
dictionary contents are still in use (so it is ok to delete them from
the dictionary). I've thought about creating a dict subclass that counts
the number of assignments and deletions but that seems cumbersome (an
bug-prone).

Is there a way to get the reference count of these datadict items? I
imagine that this would be a more stable implementation of such a feature.

Hope this gets my problem accross; if not just bash me and I'll
reformulate. I'm not the best of explainers.

Oh, and sorry if the solution to my problem is obvious (such as an
__refcount__ attribute or some stupid oversight like that).

Direct answer: sys.getrefcount()

Better answer: look at the weakref module, especially at the various
Dict helper classes.

Just
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top