Search Postgresql Archives

Re: plpythonu memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 14, 2011 at 19:14, Daniel Popowich <danielpopowich@xxxxxxxxx> wrote:
[ snip ]

> CREATE FUNCTION pygaps(start_ts timestamp without time zone, end_ts timestamp without time zone, gap_length interval) RETURNS SETOF timerange
> Â ÂLANGUAGE plpythonu
> Â ÂAS $$
>
> Â Â# because pg passes date/time to python as strings I'm using pg to
> Â Â# recompute values as seconds so I have numbers to do math
>
> Â Âgap = plpy.execute("select extract(epoch from '%s'::interval) as sec"
> Â Â Â Â Â Â Â Â Â Â Â % gap_length)[0]['sec']
>
> Â Âresults = plpy.execute("""select ts, extract(epoch from ts) as epoch
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âfrom timeseries
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âwhere ts between '%s' and '%s'"""
> Â Â Â Â Â Â Â Â Â Â Â Â Â % (start_ts, end_ts))
> Â Âif results.nrows() < 2:
> Â Â Â Âreturn
>
> Â Â# prime the well by setting prev(ious) to the first tic and
> Â Â# iterate starting with the second...
> Â Âprev = results[0]
> Â Âfor curr in results[1:]:

FYI if I don't use a slice copy here I can't get it to leak. ( find my
test case at the end ) I don't know enough about python to know if
thats a pl/python issue or python doing what its told--  having never
really wrote any python myself.

---------------
-- leaks big time
CREATE  or replace FUNCTION pygaps_leak() RETURNS void
   LANGUAGE plpythonu
   AS $$
results = plpy.execute("""select generate_series(0, 1000000)""")
prev = results[0]
for curr in results[1:]:
  prev = curr
return

-- does not leak
CREATE  or replace FUNCTION pygaps_no_leak() RETURNS void
   LANGUAGE plpythonu
   AS $$
results = plpy.execute("""select generate_series(0, 1000000)""")
prev = results[0]
for curr in range(1, len(results)):
  prev = curr
return

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux