guillaume ranquet wrote:
> this is how I convert the xml into "plottable" arrays:
> 
> def getnamefrom(name,src,what):
>     """extracts timestamps and 'what' from 'src' for 'name'"""
>     buffwhat = []
>     bufftime = []
>     sortedbyname = []
>     [sortedbyname.append(element) for
>     element in src if
>     element["name"] == name]
>     for i in sortedbyname[:-1]:
>         if i['name'] == name:
>             bufftime.append(i["timestamp"]/1e9)
>             buffwhat.append(i[what])
>     return buffwhat,bufftime
> 
> x,y = getnamefrom("cpu0",cpustat,"usage")
> plt.plot(x,y)
> del cpustat
> 
> 
> (yes, it's a hardware monitor :D)
> basically, it seems cpustat is still refcounted somewhere.

what is cpustat? ans elementtree? Anyway, it sure looks like x and y 
should be full of copies of the data, so you don't have any references 
that would keep cpustat alive.

Also, it looks like x and y are lists -- when you pass those into MPL, 
they will be copied to numpy arrays, so you can delete them too, jsut in 
case they are keeping references to cpustat items.

 > I wonder if I should append(copy.copy(i[...])) instead?

rather than that, I'd copy to numpy arrays explicitly:

return np.array(buffwhat), np.array(bufftime)

That's what MPL uses internally anyway, and you'll be clear what you 
want. If you know how many items you'll have to begin with, you can put 
the data into np.arrays directly (np.arrays do not support appending).

> or If I'm mis-interpreting what I see with top.

you could be -- Python does not necessarily give memory back to the 
system when it's done with it -- but it should be able to re-use it.

 > I'm trying  to get infos directly from the gc atm.

you could use sys.getrefcount() (note that it creates a reference 
itself, so it's always at least 2), but that may nothelp, as it may not 
be the elementree that has multiple references, but rather something 
inside it....This is very tricky business -- Python frees you from 
worrying about memory management almost all the time, but it does mean 
that you give up control.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to