I think the way to solve this problem is to run your type library through makepy.py and keep the output. For example:
C:~\Lib\site-packages\win32com\client\makepy.py -o MyTlb.py [my_path]\MyTlb.tlb

Then, in your code, wherever you need something from that type lib, import the file as you would any other package:
import MyTlb

Now you don't have to rerun makepy or gen_py or gencache or whatever every time you run your program. You don't have to include EnsureDispatch in your calls, either, because all the objects fully defined in MyTlb.py. They are the specific objects from that type lib, not generic COM objects. You just use them.

Of course, you have to watch for updates to the type library, because your Python code will not get them automatically this way. You have to rerun makepy manually each time the TLB changes. But it prevents these other problems.

Gregory W. Antal
Senior Technical Advisor
ATA Engineering, Inc.
11995 El Camino Real, Suite 200	
San Diego, CA  92130
www.ata-e.com

greg.an...@ata-e.com
858-480-2072  (Phone)
858-792-8932  (Fax)


Petr Dlabal wrote, On 7/13/2010 1:23 AM:
Hi,
I have a similar problem as described bellow - launching multiple
instances of my application causes rewriting dicts.dat file in gen_py
cache, sometimes when two processes running at the same time it leads
to errors, because of locked dicts.dat.
Is there some way to prevent this file to rewrite at every EnsureDispatch()?
I tried to set it readonly ->
<type 'exceptions.IOError'>: [Errno 13] Permission denied:
'C:\\Python26\\lib\\site-packages\\win32com\\gen_py\\dicts.dat'
      args = (13, 'Permission denied')
      errno = 13
      filename = r'C:\Python26\lib\site-packages\win32com\gen_py\dicts.dat'
      message = ''
      strerror = 'Permission denied'

(I am launching the script from cgi environment)

Thanks for any help

Peter

On Tue, Jul 21, 2009 at 8:28 PM, Paul Hudson <phudson1...@gmail.com> wrote:
  
Hi,

I am having a similar problem when launching multiple instances of an
Application that allows Python scripting via COM.  (Yes, I am launching
these instances at the same time.)

The error I get is:

  File "C:\Python26\Lib\site-packages\win32com\client\makepy.py", line 288,
in GenerateFromTypeLibSpec
    os.rename(outputName + ".temp", outputName)
<type 'exceptions.WindowsError'>: [Error 32] The process cannot access the
file because it is being used by another process
pythoncom error: Unexpected exception in gateway method 'AddTypeLib'

As stated below, I understand the gen_py folder is not thread-safe.  The
behavior I am seeing suggests many of the __init__.py files are being
rewritten every time an instance of my App initiates Python.  Is this normal
win32com.client implementation?  If I am using the same App day after day,
do the gen_py folders and files need rewritten constantly?  Is there a way
to tuck away the gen_py files for this App into a more permanent location?


Thanks,
Paul

    
---------------Original Message----------------------

On 5/02/2009 9:40 AM, Zdenek Mejzlik wrote:
      
File "c:\python25\lib\site-packages\win32com\client\gencache.py", line
109, in _LoadDicts
version = p.load()
EOFError
        
This is an error loading 'dicts.dat' from the win32com\gen_py directory.
  The management of this file is very crude and doesn't protect against
threads or processes stomping on other.

Does you app create COM objects on different threads, or are there

multiple instances of your app starting at the same time?  If so, we
might like to instrument the code to see if this indeed the problem.

      
If I uninstall both pywin and Python and install them again the problem
        
disappears. But it is only temporary
solution the problem returns back after several days. Please, help me to
find the definitive solution.
        
A quicker workaround should be to remove dicts.dat, or indeed, the

contents of the entire gen_py directory (but don't remove the directory
itself, or makepy will assume it can't write to win32com and use a
gen_py under %TEMP%.)

Cheers,

Mark
      
_______________________________________________
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
  
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to