Skip to content

Commit

Permalink
Decrease the chances of incomplete cache file
Browse files Browse the repository at this point in the history
  • Loading branch information
vijairaj committed Mar 13, 2017
1 parent 0158d7f commit 7e9a5c6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions comtypes/client/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,9 @@ def _CreateWrapper(tlib, pathname=None):

# generate the module since it doesn't exist or is out of date
from comtypes.tools.tlbparser import generate_module
if comtypes.client.gen_dir is None:
import cStringIO
ofi = cStringIO.StringIO()
else:
ofi = open(os.path.join(comtypes.client.gen_dir, modname + ".py"), "w")
import cStringIO
ofi = cStringIO.StringIO()

# XXX use logging!
if __verbose__:
print "# Generating comtypes.gen.%s" % modname
Expand All @@ -184,7 +182,8 @@ def _CreateWrapper(tlib, pathname=None):
sys.modules[fullname] = mod
setattr(comtypes.gen, modname, mod)
else:
ofi.close()
with open(os.path.join(comtypes.client.gen_dir, modname + ".py"), "w") as fd:
fd.write(ofi.getvalue())
mod = _my_import(fullname)
return mod

Expand Down

0 comments on commit 7e9a5c6

Please sign in to comment.