[python-win32] Silent crashes in calls to a COM object in Python

Mark Hammond mhammond at skippinet.com.au
Tue Apr 24 07:07:39 CEST 2012

On 24/04/2012 2:55 PM, Deniz Pelvan wrote:
> Hello Mark,
> As I mentioned, I ran my COM interface with another Win32 test app under
> a MSVC debugger for hours without any problem. I attached a debugger to
> the Python process but with Python, the script goes all the way to that
> call, waits about a minute in that call and then without throwing any
> exceptions or errors, the script stops running (i.e. the next line in
> the script never gets called) and Python drops back to the prompt.
> Nothing gets caught by the debugger.

I'm not quite with you here - I assume Python is using an inproc version 
of your object, so the COM call made by Python is actually a direct call 
into your object.  In that scenario, I can't see how execution will 
return to Python without your object actually returning.

If it is not an inproc object, then it may be that the default COM 
marshaller is indeed timing out, but I'm not familiar with that or under 
what circumstances this will happen but it might be worth looking at 
what "apartment" things are running in, and/or any other differences 
between the environment your test app runs under and that of Python.

I'm also not sure what prompt you are referring to - the Python prompt 
or a cmdline prompt?  Either way, with the debugger you should be able 
to see the call to IDispatch::Invoke made by Python (hrm - but sadly you 
will probably need to build pywin32 yourself so you get debugging 
symbols).  If you can see that call to Invoke(), you should be able to 
determine if that call never returns (in which case it is almost 
certainly the marshaller) or if it returns with an error code or 0.

There isn't much else in Python or pywin32 that can help - depending on 
how you construct the COM object, there are one or 2 places where the 
Python code calls "dispatchobject.Invoke()" (or 
dispatchobject.InvokeTypes()) which is basically a direct call from the 
interpreter into win32com/src/PyIDispatch.cpp - the debugger is the best 
tool for that...


> I was wondering if there are any options either in the Python
> interpreter or in pywin32 (or maybe a debug version) that can show what
> is happening internally, especially over the COM dispatch...
> Thanks in advance
> Deniz
>  > Date: Tue, 24 Apr 2012 11:08:12 +1000
>  > From: skippy.hammond at gmail.com
>  > To: i_pelvan at hotmail.com
>  > CC: python-win32 at python.org
>  > Subject: Re: [python-win32] Silent crashes in calls to a COM object
> in Python
>  >
>  > Python and pywin32 don't impose any time limits for timeouts and I can't
>  > think of what could cause this other than (say) an exception handler in
>  > your script that ignores exceptions and terminates the process. Even if
>  > Python actually crashed I'd expect Windows to show the "app crashed"
>  > dialog. If you have MSVC you could try running the python process under
>  > it to see if it reports anything strange.
>  >
>  > Mark
>  >
>  > On 24/04/2012 8:09 AM, Deniz Pelvan wrote:
>  > >
>  > > Hello guys,I am having trouble with the Python interpreter crashing
>  > > silently (no exceptions or errors thrown) when I make a call to a
>  > > very CPU-intensive method in my COM/ATL component using Pywin32. The
>  > > method is an FFT analysis for audio files and hits about 25% CPU on a
>  > > single core and runs for about 1 minutes. I have tested the COM
>  > > method intensively via normal win32 applications and there are no
>  > > problems with it (I can run the same method over and over again 1000s
>  > > of times in a win32 app).- Also the same Python script (with a call
>  > > to this COM method) will run successfully on different machines and
>  > > will fail at the same machine only randomly (i.e. on some machines,
>  > > it never fails, while on others, it has ~50% failure rate). - This
>  > > specific method is the most CPU-intensive one in the COM component
>  > > and other methods do not fail on any of the machines. Because of
>  > > this, I think the problem might have something to do with either the
>  > > CPU usage or a timeout feature on Python or pywin32. Are there any
>  > > tools that would help me narrow down the cause or maybe increase the
>  > > CPU/time limits for Python/PyWin32? I haven't seen anything in the
>  > > documentation that'd help.Thanks in advanceDeniz Pelvan
>  > > _______________________________________________ python-win32 mailing
>  > > list python-win32 at python.org
>  > > http://mail.python.org/mailman/listinfo/python-win32
>  > >
>  >
>  >

More information about the python-win32 mailing list