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 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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |