From: | Alex Hunsaker <badalex(at)gmail(dot)com> |
---|---|
To: | Daniel Popowich <danielpopowich(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: plpythonu memory leak |
Date: | 2011-01-17 23:47:43 |
Message-ID: | AANLkTin+xUH+2P4sPu5v3_zTRq0eSMNH6OHu030TRpGS@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Jan 14, 2011 at 19:14, Daniel Popowich <danielpopowich(at)gmail(dot)com> 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
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2011-01-18 01:22:09 | Re: Install PostgreSQL as part of a desktop application, but how to coop with existing installations? |
Previous Message | raf | 2011-01-17 23:33:35 | Re: help understanding collation order |