psycopg2-ctypes icon indicating copy to clipboard operation
psycopg2-ctypes copied to clipboard

RuntimeError + all system memory consumed

Open philipn opened this issue 12 years ago • 5 comments

Using psycopg2-ctypes and pypy I see:

Exception RuntimeError: RuntimeError('maximum recursion depth exceeded',) in method __del__ of <psycopg2ct._impl.cursor.Cursor object at 0x000000000623a230> ignored

printed by the django development server. It only happens sometimes, and when it does happen it causes the server to lock up and all memory on my system to be consumed. I can't seem to generate a traceback

This doesn't always happen. Sometimes (for tiny pages in my app) I can get pypy/django/psycopg-ctypes to respond without issue. But for DB-heavy pages it seems to throw this and then just stall.

philipn avatar Mar 17 '12 04:03 philipn

Try setting DEBUG to False and see if you still run into this.

gtaylor avatar Mar 17 '12 05:03 gtaylor

I am seeing this with DEBUG = False as well.

philipn avatar Mar 17 '12 05:03 philipn

Would it be possible to get a traceback of it? You may wrap the __del__ method content in a try-except and print it when it happens using the "traceback" method.

dvarrazzo avatar Mar 20 '12 17:03 dvarrazzo

I tried repeatedly to get a traceback and failed. #pypy said that the del method is weird and it's not unexpected that I wouldn't be able to get one.

On Mar 20, 2012, at 10:15 AM, Daniele [email protected] wrote:

Would it be possible to get a traceback of it? You may wrap the del method content in a try-except and print it when it happens using the "traceback" method.


Reply to this email directly or view it on GitHub: https://github.com/mvantellingen/psycopg2-ctypes/issues/23#issuecomment-4600449

philipn avatar Mar 20 '12 17:03 philipn

This is only a shot in the dark: the method is:

    def __del__(self):
        if self._pgres:
            libpq.PQclear(self._pgres)
            self._pgres = None

this is absolutely not thread safe. Could you test with something like:

    def __del__(self):
        pgres = self.__dict__.pop('_pgres', None)
        if pgres is not None:
            libpq.PQclear(pgres)

which is sort of atomic, as long pop is?

Again, this is only shotgun debugging, not that I really understand what's going on, nor it makes any sense at all. Bug in PyPy?

dvarrazzo avatar Mar 20 '12 18:03 dvarrazzo