Fatal Python error: GC object already in linked list

Jimmy Retzlaff jimmy at retzlaff.com
Tue May 14 15:53:39 EDT 2002


I wrote:
> I'm working on an application in Python and my application
> occasionally dies with the error:
>
>  Fatal Python error: GC object already in linked list

I've upgraded to 2.2.1 and spent 4 days trying to isolate the problem.
I've given up for now (I've found a workaround described below) but I
wanted to follow up here in case anybody is still reading. :)

In 2.2.1 the problem is still there, but it's not as consistent. In
2.2 I recreated the problem 5-10 times within the Visual Studio
debugger, and each time it involved memory management of a tuple at
the same point in my Python code. In 2.2.1 it happened at various
locations and sometimes involved a tuple and other times involved an
integer. The message also varied to include things like UNREFing an
invalid object.

I tried isolating the problem by removing parts of my application.
This proved very difficult as seemingly random combinations of things
made the problem go away (e.g., the problem would happen with just
about any 2 of my 15-20 major UI components present but no one UI
component alone would exhibit the problem). The one consistent way to
make the problem go away was to shut down my one and only background
thread. In an isolated case that thread was simply executing:

x = []
while 1:
    if x:
        assert 0 # make sure we never get here in this test case
    else:
        time.sleep(0.1)


With the above code in a second thread, my application would
consistently exhibit the problem in the main thread within 5 hours.
With the above thread not running the application ran for 3 days on
one machine and 2 on another and never exhibited the problem. I then
re-implemented the background thread:

import Queue
x = Queue.Queue()
while 1:
    x.get()
    assert 0 # make sure we never get here in this test case

I made this change yesterday and now the application has been running
for nearly 24 hours with no problem. I know there have been changes in
wxPython's handling of the Global Interpreter Lock in recent CVS
versions (I'm using the 2.3.2.1 release from www.wxpython.org). The
memory management issues consistently involve objects created by calls
into wxPython APIs, so at this point I'm guessing the problem lies
within wxPython/SWIG/wxWindows - I only wish I had the time to isolate
it further.

But since the problem is gone for now, I need to move on.

Jimmy

p.s. - For those of you who, like me, are lucky enough to use Python
almost exclusively for your work, you should occasionally return to
the C/C++ edit/build/debug cycle to make it crystal clear how good you
have it with Python. I had forgotten why debuggers were so necessary!



More information about the Python-list mailing list