diff --git a/CHANGES b/CHANGES
index 0668542a3c9979fdaef96b1f7111455b74882c3c..13c7da06d3af3fe361387287c6baa47e53b9f84b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,14 @@
   line contains no line number, as in when
   inside an eval/exec-generated function.
   [ticket:132]
+
+- When a .py is being created, the tempfile
+  where the source is stored temporarily is
+  now made in the same directory as that of
+  the .py file.  This ensures that the two
+  files share the same filesystem, thus 
+  avoiding cross-filesystem synchronization
+  issues.  Thanks to Charles Cazabon.
   
 0.3.2
 - Calling a def from the top, via 
diff --git a/mako/template.py b/mako/template.py
index 8e932875e125b20e6d6236bfc743365f77538893..2aed7a7e11705c13291c04eca738b69bb5440723 100644
--- a/mako/template.py
+++ b/mako/template.py
@@ -390,7 +390,11 @@ def _compile_module_file(template, text, filename, outputpath):
                                 imports=template.imports,
                                 source_encoding=lexer.encoding,
                                 generate_magic_comment=True)
-    (dest, name) = tempfile.mkstemp()
+                                
+    # make tempfiles in the same location as the ultimate 
+    # location.   this ensures they're on the same filesystem,
+    # avoiding synchronization issues.
+    (dest, name) = tempfile.mkstemp(dir=os.path.dirname(outputpath))
     
     if isinstance(source, unicode):
         source = source.encode(lexer.encoding or 'ascii')