mvantellingen / psycopg2-ctypes

ctypes port of psycopg2 (see https://github.com/chtd/psycopg2cffi)
Other
56 stars 59 forks source link

RuntimeError + all system memory consumed #23

Open philipn opened 12 years ago

philipn commented 12 years ago

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.

gtaylor commented 12 years ago

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

philipn commented 12 years ago

I am seeing this with DEBUG = False as well.

dvarrazzo commented 12 years ago

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.

philipn commented 12 years ago

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 Varrazzoreply@reply.github.com 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

dvarrazzo commented 12 years ago

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?