Re: Segfault in in PyString_FromStringAndSize
"Fernando M. Maresca" <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Federico.
Thanks for your answer.
On Mon, Mar 09, 2009 at 03:23:30PM +0100, Federico Di Gregorio wrote:
> Il giorno sab, 07/03/2009 alle 12.54 -0200, Fernando M. Maresca ha scritto:
> > On Fri, Mar 06, 2009 at 10:06:04AM -0500, James Henstridge wrote:
> > > For these sort of bugs, I'd recommend using valgrind to track down the problem.
> > >
> > > First you'll need a test program that triggers the bug, but it sounds
> > > like you've got that already.
> > I can reproduce the segfault with this program (which mimics the
> > mechanics of my program, to the simplest possible form, preserving the
> > threading):
>
> Threading, uh! :( Thank you for the test case. I'll try to fix this one
> ASAP.
You're right: without threads the segfault dissapears.
The program I've showed has a problem: if the segfault doesn't get
triggered early, the filler thread will eat all of the memory. Here's a
modified one:
class F:
def __init__(self, q):
self.q = q
def run(self):
i = 1;
comm = 1;
while 1:
self.q.put((comm, str(i)))
if self.q.qsize() > 10000: time.sleep(30)
if i > 9998:
i=1
if comm > 5: comm = 1
else: comm += 1
else:
i += 1
class P:
def __init__(self, db, q):
self.q = q
self.db = db
def run(self):
while 1:
tup = self.q.get(block=True)
print "qzise", self.q.qsize()
sql = "SELECT * FROM monacct_comm WHERE comm_id=%s AND abonado= %s"
vals = [tup[0], tup[1]]
cur = self.db.conn.cursor()
print "got cur", cur
print "exec query", sql, vals
cur.execute(sql, vals)
# print "got query, result:", cur.fetchall()
print "close cur"
cur.close()
print "closed"
I've trying to get anything useful out of valgrind, but this thing is so
slow that a segfault may take a century to show up. There are several
possible leaks showed in the log of valgrind, but no one looks like the
one I' was looking for. May be the problem comes from other place.
Looking at the code in psycopg2-2.0.7 (debian testing/lenny current
version of python-psycopg package, instead of 2.0.9 in unstable/sid)
I've noted that the caller in adapter_qstring.c allocates the memory for
the buffer, and there is no provision for this inside qstring_scape()
(now replaced by utils.c psycopg_escape_string()).
Don't know how this is different at all, but I think that's something to
do with threads when this call returns and that pointer is lost.
I can't get a segfault in that version. Hope this help.
Let me know if I can help.
Thanks a lot,
--
Fernando
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc
(application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkm1Tv8ACgkQCtDmpVXdEMbROgCfdu4EFOhcdySO7ydTdZ03jVsn ifQAnjMPASCtbyEgmKSkV2Al6DatqiDE =+Jqs -----END PGP SIGNATURE-----