[python-win32] updating a registered com server

Tim Roberts timr at probo.com
Thu Apr 26 19:01:55 CEST 2007


Francesco Guerrieri wrote:
>
> ...
> I register the server with the usual
>  
> if __name__ == '__main__': win32com.server.register.UseCommandLine(....)
>  
> Then I find that I want to add/change/correct something, and I
> register it again.
> The problem is that Excel persists in calling the OLD server.
> At first I believed that it was my fault, since I hadn't changed the
> _reg_clsid_ . (more on this later). But even if I changed it, Excel
> persisted in calling the old server.
> I've found two solutions, both of them ugly:
> a) closing and restarting excel (which is way too long, and
> undesiderable since maybe I've been writing something on the sheets) or
> b) re-naming the .py file and re-running it.
> This means that I have a directory full of mySeverXX.py for XX = 1, 2,
> ... infinity  :-)
>  
> so my questions are:
> 1) is there a way to refresh the list of servers that excel looks for?
> 1b) is this in someway connected with the generated .pyc files? by
> changing the names I am forcing the interpreter to compile it again,
> am not I?
> 2) what happens if I register with the same _reg_clsid_? Is my
> registry irreversibly messed up?

You do not have to create a new clsid every time.  In fact, by doing so,
you are filling your registry with dead clsid entries.

The situation you describe would be the same even if you had written
your component in C++.  For efficiency reasons, an out-of-process COM
server does not automatically die when its last object is freed.  It
will remain in memory until the last calling process ends, or until an
app calls CoFreeUnusedLibraries.  Excel never calls that, so the only
way to free up the existing server instance is to kill Excel.

Remember that the problem you describe only occurs during development,
and we developers are used to being inconvenienced.  Once your server
stabilizes, you will be happy that the instance keeps running, so you
don't have to pay the penalty of invoking the interpreter each time.

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



More information about the Python-win32 mailing list