diff piecrust/serving.py @ 214:09e350db7f8f

serve: Don't have 2 processing loops running when using `--use-reloader`.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 31 Jan 2015 16:28:16 -0800
parents 7a5a7a7e8cee
children d7a548ebcd58
line wrap: on
line diff
--- a/piecrust/serving.py	Sat Jan 31 15:33:18 2015 -0800
+++ b/piecrust/serving.py	Sat Jan 31 16:28:16 2015 -0800
@@ -72,9 +72,17 @@
         self._out_dir = os.path.join(app.cache_dir, 'server')
         self._page_record = ServeRecord()
 
-        pipeline = ProcessorPipeline(app, self._out_dir)
-        loop = ProcessingLoop(pipeline)
-        loop.start()
+        if (not self.use_reloader or
+                os.environ.get('WERKZEUG_RUN_MAIN') == 'true'):
+            # We don't want to run the processing loop here if this isn't
+            # the actual process that does the serving. In most cases it is,
+            # but if we're using Werkzeug's reloader, then it won't be the
+            # first time we get there... it will only be the correct process
+            # the second time, when the reloading process is spawned, with the
+            # `WERKZEUG_RUN_MAIN` variable set.
+            pipeline = ProcessorPipeline(app, self._out_dir)
+            loop = ProcessingLoop(pipeline)
+            loop.start()
 
         # Run the WSGI app.
         wsgi_wrapper = WsgiServer(self)