WindowsError when renaming temporary file
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Chamelon Core |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
Following the tutorial pyramid-1.0.pdf, paragraph 5.6 on win XP I get the following at localhost:6543
I am not sure whether the bug belongs here or over at pyramid, so bear with me.
I worked around the following problem by inserting the line:
just after the line:
fd, fn = tempfile.
In the file builder.py inside ModuleLoader.build
Module pyramid.
<< except (TypeError, ValueError):
>> result = self.template(
Module chameleon.
<< def __call__(self, **kwargs):
def __repr__(self):
>> return self.render(
Module chameleon.
<< setdefault(
def include(self, stream, econtext, rcontext):
>> return super(PageTemplate, self).render(
Module chameleon.
<< stream = self.output_
try:
>> self.cook_check()
Module chameleon.
<< if self._cooked is False:
def detect_
>> self.cook(body)
Module chameleon.
<< def cook(self, body):
for name, function in program.items():
>> program = self._cook(body, digest)
Module chameleon.
<< source = "# filename: %s\n#\n%s" % (self.filename, source)
>> cooked = self.loader.
Module chameleon.
<< raise
>> os.rename(fn, name)
and furthermore (in the console)
Traceback (most recent call last):
File "C:\Python27\
func(*targs, **kargs)
File "D:\Users\
\chameleon\
shutil.
File "C:\Python27\
onerror(
File "C:\Python27\
os.
WindowsError: [Error 32] The process cannot access the file because it is being
used by another process: 'c:\\docume~
ate_8612ea41c3c
Hi
I can confirm this problem. The problem is that tempfile.mkstemp() returns a file handler to an open file which prevents os.rename from working on this file.
As a solution I close the file directly after creating the temporary file using os.close
I attached a patch for this.