1. Andrey Vlasovskikh
  2. obraz
  3. Issues
Issue #13 invalid

Crash on serve --watch if volatile files appear

Sergey Astanin
created an issue

How to reproduce:

  • open one of the posts in emacs
  • run python2 obraz.py serve --watch
  • when the server is ready, start editing the post without saving it
  • emacs may create a temporary (auto-save?) file, like _posts/.#YYYY-MM-DD-post-title.md
  • soon obraz.py crashes:
Loaded 217 files
Processing tags...
Sort and interlink posts...
Generate pages with YAML front matter...
Copy static files...
Site generated successfully
Serving at 0.0.0.0:8000
Error: [Errno 2] No such file or directory: '<snip-snip>/_posts/.#2013-09-19-good-design.md'
make: *** [serve] Error 1

The problem seems to be related to calling os.stat() in changed_files() on a file which have just disappeared. Simply intercepting the OSError resolves the problem.

diff --git a/obraz.py b/obraz.py
--- a/obraz.py
+++ b/obraz.py
@@ -193,11 +193,14 @@
     while True:
         changed = []
         for path in all_source_files(source, destination):
-            new = os.stat(path).st_mtime
-            old = times.get(path)
-            if not old or new > old:
-                times[path] = new
-                changed.append(path)
+            try:
+                new = os.stat(path).st_mtime
+                old = times.get(path)
+                if not old or new > old:
+                    times[path] = new
+                    changed.append(path)
+            except OSError:
+                pass  # cannot os.stat(path)
         if changed:
             yield changed
         sleep(poll_interval)

Comments (2)

  1. Log in to comment