pythoncom, CoUninitialize & references

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gloom

    pythoncom, CoUninitialize & references

    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_c d():
    drives = nero.GetDrives( constants.NERO_ MEDIA_CD)
    rc = None
    for d in drives:
    if d.DeviceName.fi nd("BACKPACK") != -1:
    rc = d
    break
    del(drives)
    print rc
    return rc

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

    if __name__ == "__main__":
    main()
    print pythoncom._GetI nterfaceCount()
    pythoncom.CoFre eUnusedLibrarie s()
    pythoncom.CoUni nitialize()

    # end of sample code

    the problem is as follows, if for example, I remove the line
    'del(nero)' in function main(), the _GetInterfaceCo unt() 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.
Working...