# HG changeset patch # User Ludovic Chabant # Date 1422750496 28800 # Node ID 09e350db7f8f1805651ade65a3def2a77a520635 # Parent e34a6826a3d494eadd22de9fe21e789b6f326138 serve: Don't have 2 processing loops running when using `--use-reloader`. diff -r e34a6826a3d4 -r 09e350db7f8f piecrust/serving.py --- 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)