473,396 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

referrers

Hi All,

The sys.getrefcount() is very useful to get the number of references on
a particular object.

Is there any companion function to get "who" the referrers are ?

for e.g.

global x
global y
global z
x0=24012
y=x0
z=x0

print "ref count ",sys.getrefcount(x0)
This prints a ref count of 5.

Basically, I need to know which are the 5 entities who are referring to
x0 ?

Is there any way of doing it ?

Thanks.

Bye,
raghavan V

May 24 '06 #1
3 1412
raghu wrote:
Hi All,

The sys.getrefcount() is very useful to get the number of references on
a particular object.

Is there any companion function to get "who" the referrers are ?

for e.g.

global x
global y
global z
x0=24012
y=x0
z=x0

print "ref count ",sys.getrefcount(x0)
This prints a ref count of 5.

Basically, I need to know which are the 5 entities who are referring to
x0 ?

Is there any way of doing it ?


Look into the gc-module.

Diez
May 24 '06 #2
Diez,

I did look into gc, specifically gc.get_referrers(), but it seemed to
give me something that I cant decipher.

I added the following line.

print "referrers ",gc.get_referrers(x0)

This is what I got.

referrers [{'__builtins__': <module '__builtin__' (built-in)>,
'__file__': './tst1.py', 'pdb': <module 'pdb' from
'/home/raghavan/Python-2.4/my_install/lib/python2.4/pdb.pyc'>, 'sys':
<module 'sys' (built-in)>, 'y': 24012, 'gc': <module 'gc' (built-in)>,
'myfuncs': <module 'myfuncs' from '/home/Raghavan/tst/myfuncs.dll'>,
'__name__': '__main__', 'x0': 24012, 'z': 24012, 'os': <module 'os'
from '/home/raghavan/Python-2.4/my_install/lib/python2.4/os.pyc'>,
'__doc__': None, 'types': <module 'types' from
'/home/raghavan/Python-2.4/my_install/lib/python2.4/types.pyc'>},
(None, '/home/Raghavan/tst', 'my pid is ', 24012, 'ref count ',
'referrers ')]

Also the len of this is 2, while I got refcount=5. So I dont know
whether this can be used in the same way.

Thanks.

Bye,
Raghavan V

May 24 '06 #3
raghu wrote:
Diez,

I did look into gc, specifically gc.get_referrers(), but it seemed to
give me something that I cant decipher.

I added the following line.

print "referrers ",gc.get_referrers(x0)

This is what I got.

referrers [{'__builtins__': <module '__builtin__' (built-in)>,
'__file__': './tst1.py', 'pdb': <module 'pdb' from
'/home/raghavan/Python-2.4/my_install/lib/python2.4/pdb.pyc'>, 'sys':
<module 'sys' (built-in)>, 'y': 24012, 'gc': <module 'gc' (built-in)>,
'myfuncs': <module 'myfuncs' from '/home/Raghavan/tst/myfuncs.dll'>,
'__name__': '__main__', 'x0': 24012, 'z': 24012, 'os': <module 'os'
from '/home/raghavan/Python-2.4/my_install/lib/python2.4/os.pyc'>,
'__doc__': None, 'types': <module 'types' from
'/home/raghavan/Python-2.4/my_install/lib/python2.4/types.pyc'>},
(None, '/home/Raghavan/tst', 'my pid is ', 24012, 'ref count ',
'referrers ')]

Also the len of this is 2, while I got refcount=5. So I dont know
whether this can be used in the same way.


The refcount is always precise - as it is a simple integer that happens to
be part of every python object. But the 1:n-relation to its referres is
computed and not necessarily complete, as the docs state very clear.

Additionally, they state that this method is only to be used for
debugging-purposes.

I'm not sure what you are after here - if it is about solving a mem-leak, gc
might help. If it is some application logic, the advice must be clearly to
explicitly model the object graph bi-directional.

Diez
May 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jason Brown | last post by:
I've been looking for a script that will create a real-time list of 'top referrers', similar to the links to sites you see on the left of the page at http://www.linkswarm.com. They also have a page...
6
by: Chris S. | last post by:
I'm trying to make a graphical editor and browser for Pickled files. One aspect I'm not sure about is how to detect multiple references to the same data. For instance, say I had the Pickled...
2
by: F. Petitjean | last post by:
I have written a script to find the modules which export the largest number of names. The gc.getreferrers(*objs) function gives also an idea of the dependencies between the modules. The code...
23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
27
by: Lee Phillips | last post by:
I believe it is universally accepted that decorating your website with images from someone else's, without permission, is rude and unethical, even if the images are in the public domain, because...
1
by: Ben Fidge | last post by:
I'm working on an application that does a load of processing on Session_Start if a new session is started having come from a particular referrer. To determine this I use Request.UrlReferrer. How...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
1
by: FightClubDiego | last post by:
Hey.. I've been working on these sign up / log in forms for my new Game Site, and everything else in the game works but the registration!! I keep ketting the unexpected $end and Im tired of it! Here...
5
by: The Big One | last post by:
8-7-2008 Hello, Our hosting provider has changed his server to PHP5. I have a PHP file that normaly gives the custumor an email, and i get one mail. Now the server has changed i only get my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.