pythoncom, CoUninitialize & references

gloom o_gloom at mail.com
Thu Mar 11 13:16:35 CET 2004


Hey,

I'm programming something with NeroSDK COM module, and I bumped into a
problem:
why doesn't python releases and uninitializes COM objects that are no
longer referenced?

Here is a sample code:
# start of sample code
from win32com.client import *

nero = None

def find_backpack_cd():
    drives = nero.GetDrives(constants.NERO_MEDIA_CD)
    rc = None
    for d in drives:
        if d.DeviceName.find("BACKPACK") != -1:
            rc = d
            break
    del(drives)
    print rc
    return rc

def main():
    global nero
    nero = Dispatch("Nero.Nero")
    cd = find_backpack_cd()
    del(cd)
    del(nero)

if __name__ == "__main__":
    main()
    print pythoncom._GetInterfaceCount()
    pythoncom.CoFreeUnusedLibraries()
    pythoncom.CoUninitialize()
 
# end of sample code

the problem is as follows, if for example, I remove the line
'del(nero)' in function main(), the _GetInterfaceCount() is 1 and
CoUninitialize() fails.
And if I remove the explicit call to CoUninitialize() (and the
interface count is greater than 0) the next time I run the program it
fails with exception that the neroAPI is already initialized (deducing
that it is somehow still in memory).

Doesn't python should get rid of all instances of the COM objects
through its garbage collector?


Thanks,
Omer.



More information about the Python-list mailing list