win32com.client problem

Discussion in 'Python' started by It's me, Jan 5, 2005.

  1. It's me

    It's me Guest

    I've been using the win32com module with very good success in placing data
    onto an Excel spreadsheet. However, whenever I have an error in my script
    (like mapping a non-square array onto the spreadsheet), something breaks.
    After fixing my error and restart the Python program again, Excel would
    start up a window with a "Microsoft Excel - BookX" where X is a increasing
    number (1,2,3,4,....) instead of just 1. Then, the spreadsheet portion of
    the screen is hidden - I can only see the menu bars (on top).

    If I restart the computer, run the Python script again and Excel would
    behave fine and it would start with "Microsoft Excel - Book1" everytime.

    My guess is that there is a zombie Excel process that got stuck in the
    system. However I couldn't tell for sure by looking at the Process Manager

    Any idea how I can prevent this?

    It's me, Jan 5, 2005
    1. Advertisements

  2. It's me

    Kartic Guest


    1. Put your COM invokations in a try/except loop. From my experience,
    that helped me prevent, in most cases, Excel from "hanging" and having
    to restart the PC too. In the except part, release the Excel (or other
    COM resource) (e.g.calling workbook.Close() or excelobj.Quit(),
    depending on the state of your program)

    2. Look at
    to see how to get the actual error.

    3. Delete instances of the COM connection, RS object or whatever
    win32com.client instances you create. I do this:
    sheetobj = None
    wbkbobj = None
    excelobj = None
    del sheetobj
    del wbkobj
    del excelobj

    4. At the end of my scripts, I do the following during the development
    ActiveComConn = pythoncom._GetInterfaceCount()
    print 'Done! Active Com Connections :',ActiveComConn # Print count of
    Active COM connections.

    Thank you,
    Kartic, Jan 5, 2005
    1. Advertisements

  3. It's me

    It's me Guest

    Thanks for the reply. I will chew on this a bit.
    It's me, Jan 5, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.