launch vim -> update file -> launch msvc -> file locked
launch vim -> update file -> launch msvc -> close vim -> file locked
launch vim -> update file -> -> close vim -> launch msvc -> file okay
Update code is something like that:
backup_file_name = '<some file name>'
with open(backup_file_name, 'w') as backup_file:
input = sax.make_parser()
output = saxutils.XMLGenerator(backup_file, 'cp1252')
filter = __vcproj_config_filter('<updated file name>', input, output)
filter.parse('<updated file name>')
shutil.copyfile(backup_file_name, '<updated file name>')
os.remove(backup_file_name)
__vcproj_config_filter is a descent of a XMLFilterBase; it substitutes
some attributes in xml file and that's all.
must be noted that __vcproj_config_filter instance holds reference to
output (sax xml parser) object.
Is the code above contained in a function? So all references are released
upon function exit?
If not, you could try using: del input, output, filter
That should release all remaining references to the output file, I
presume. Or locate the inner reference to the output file
(filter.something perhaps?) and explicitely close it.
--
Gabriel Genellina
Yes, it's a function
> If not, you could try using: del input, output, filter
> That should release all remaining references to the output file, I presume.
> Or locate the inner reference to the output file (filter.something perhaps?)
> and explicitely close it.
That doesn't help either.
When I've rewrite code something like that:
with open(backup_file_name, 'w') as backup_file:
.....
filter.parse('<updated file name>')
del input, output, filter
os.remove(project.get_vcproj())
os.rename(backup_file_name, project.get_vcproj())
It triggers WindowsError on os.remove()
Using "programming by permutation" pattern I've finally solved that
thing: filter
for some reason doesn't close file after XMLFilterBase.parse(<file_name>);
even after del filter; Workaround for this is to pass <file_descriptor>
instead of <file_name> to XMLFilterBase.parse() and then explicitly close
file or put this call in with-block.