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
    list.

    Any idea how I can prevent this?

    Thanks,

    --
    Me
     
    It's me, Jan 5, 2005
    #1
    1. Advertising

  2. It's me

    Kartic Guest

    Hi,

    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
    http://www.faqts.com/knowledge_base/entry/versions/index.phtml?aid=5847
    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
    stage:
    ActiveComConn = pythoncom._GetInterfaceCount()
    print 'Done! Active Com Connections :',ActiveComConn # Print count of
    Active COM connections.

    Thank you,
    --Kartic
     
    Kartic, Jan 5, 2005
    #2
    1. Advertising

  3. It's me

    It's me Guest

    Thanks for the reply. I will chew on this a bit.

    "Kartic" <> wrote in message
    news:...
    > Hi,
    >
    > 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
    > http://www.faqts.com/knowledge_base/entry/versions/index.phtml?aid=5847
    > 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
    > stage:
    > ActiveComConn = pythoncom._GetInterfaceCount()
    > print 'Done! Active Com Connections :',ActiveComConn # Print count of
    > Active COM connections.
    >
    > Thank you,
    > --Kartic
    >
     
    It's me, Jan 5, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin Stockton
    Replies:
    1
    Views:
    474
    Trent Mick
    Nov 12, 2003
  2. Stefano Masini
    Replies:
    2
    Views:
    1,288
    Markus Wankus
    Mar 6, 2004
  3. Replies:
    2
    Views:
    1,348
  4. Ray
    Replies:
    1
    Views:
    540
  5. Dave Angel

    Re: win32com.client import problem

    Dave Angel, Oct 14, 2009, in forum: Python
    Replies:
    0
    Views:
    648
    Dave Angel
    Oct 14, 2009
Loading...

Share This Page