Thanks for your reply Tim. "* I couldn't reproduce the crash after a few times on my Win7 x64 with Office 2003, Python 2.7, pywin32 2.1.4. I note that you said it only crashed 1 time in 3 so perhaps I didn't try hard enough, but there may be some version-sensitivity there as well."
I am using Office 2007, opening a 2003 file, with Python 2.5. My version of pywin32 is build 214. I think that is the same as 2.1.4? Sometimes it did take me a while to get it to come up, so I am not surprised if it didn't come up for you (if it will happen at all). I have had it several times in a row though. "* In general, you don't need to go unsetting sheet or book or whatever (unless you have some requirement which is unstated here). If you get rid of the "sheet=None" etc. lines, does the crash still occur?" I removed the "=None" lines as you suggested. It took me many more tries than before to get the error to come up, but eventually it did. "* The underlying problem is almost certainly going to be a subtle timing interaction around the refcounting on the pywin32 CDispatch objects which are proxying for the underlying Windows objects. It's a maze of twisty passages, so I'll let Mark or Roger comment if they think there's something to be said." If this is true, I hope to get some advice on how to correct the problem. My previous implementation opened the Excel file at a previous point in the program, then later read in the sheets, and then even later closed the file, with possible minutes in between each of these. I never saw the error with this implementation, however it gave the opportunity to the user to interact with their own instance of Excel, potentially causing problems for the instance I created (previous mailing list e-mail: http://mail.python.org/pipermail/python-win32/2011-May/011494.html). So I had to change it so that the new Excel is opened to get the sheet names and then immediately closed. Again, thanks for your response. Any help is appreciated. Mark -----Original Message----- From: python-win32-bounces+mark.mordeca=prosensus...@python.org [mailto:python-win32-bounces+mark.mordeca=prosensus...@python.org] On Behalf Of Tim Golden Sent: Tuesday, May 31, 2011 4:09 AM To: python-win32@python.org Subject: Re: [python-win32] Excel "stopped working" after reading in sheet names On 30/05/2011 21:26, Mark Mordeca wrote: > Greetings, > > I would appreciate any help I could get with the following problem. 30% > of the time after running the following code to get the sheet names out > of an excel file, I will receive a windows error saying that "Microsoft > Office Excel has stopped working". A few points: * The underlying problem is almost certainly going to be a subtle timing interaction around the refcounting on the pywin32 CDispatch objects which are proxying for the underlying Windows objects. It's a maze of twisty passages, so I'll let Mark or Roger comment if they think there's something to be said. * I couldn't reproduce the crash after a few times on my Win7 x64 with Office 2003, Python 2.7, pywin32 2.1.4. I note that you said it only crashed 1 time in 3 so perhaps I didn't try hard enough, but there may be some version-sensitivity there as well. * In general, you don't need to go unsetting sheet or book or whatever (unless you have some requirement which is unstated here). If you get rid of the "sheet=None" etc. lines, does the crash still occur? * As an aside: your for sheet in book.Sheets: loop is basically a list comprehension in disguise: sheetList = [sheet.Name for sheet in book.Sheets] Some people don't feel comfortable with list comps which may be your case. But just in case you weren't even aware of the possiblility, I thought I'd offer it for your further englightenment :) TJG _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32