Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > win32com.client problem

Reply
Thread Tools

win32com.client problem

 
 
It's me
Guest
Posts: n/a
 
      01-05-2005
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


 
Reply With Quote
 
 
 
 
Kartic
Guest
Posts: n/a
 
      01-05-2005
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/...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

 
Reply With Quote
 
 
 
 
It's me
Guest
Posts: n/a
 
      01-05-2005
Thanks for the reply. I will chew on this a bit.

"Kartic" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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/...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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments