[python-win32] Shell extension debugging

Tim Roberts timr at probo.com
Mon Jun 29 21:09:21 CEST 2009


Gertjan Klein wrote:
> It doesn't over here, but another poster has shown me how to circumvent
> this. If this is the only way to do that I will; there is no way to tell
> PyWin32 to reload the extension? (I know reloading in Python is tough,
> I'm expecting a "no" here. ;-))
>   

I was going to respond "no" immediately, but now you've got me
thinking.  Explorer loads the DLL, instantiates the COM object, and
keeps it loaded forever.  I think that fact alone makes it impossible;
even if you added a backdoor to reload the module, you still have an
object in memory using the original implementation.

> The logging module reminds me of Java too much. :(  I think I'll try to
> write to a file, I have no idea if I have a kernel debug log monitor.
>   

Oh, don't be afraid of the logging module.  Logging to stderr is as
simple as:
    >>> import logging
    >>> logging.basicConfig( level=logging.INFO )
    >>> logging.info( "This is an info message" )
    INFO:root:This is an info message

To send to a file instead:
    import logging
    logging.basicConfig( filename='/tmp/mylog.txt', level=logging.INFO )
    logging.info( "This is an info message" )

The logging module does have a billion features, and you might want to
use some of those to add a timestamp to them, but once you have gone to
the trouble of adding logging calls throughout your app, tweaking the
formatting and the framework is trivial.

> I read somewhere that debugging a C++ shell extension is possible under
> Visual Studio; can I assume that something like that is not viable when
> using Python / PyWin32?
>   

I would be very surprised.  You need to be able to attach to an existing
process, and I don't know of any Python debuggers that can do that.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list