Mercurial > piecrust2
view piecrust/wsgiutil/__init__.py @ 1188:a7c43131d871
bake: Fix file write flushing problem with Python 3.8+
Writing the cache files fails in Python 3.8 because it looks like flushing
behaviour has changed. We need to explicitly flush. And even then, in very
rare occurrences, it looks like it can still run into racing conditions,
so we do a very hacky and ugly "retry" loop when fetching cached data :(
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 15 Jun 2021 22:36:23 -0700 |
parents | d0f86d9a9d40 |
children |
line wrap: on
line source
import logging from piecrust.serving.wrappers import get_piecrust_server def _setup_logging(log_file, log_level, max_log_bytes, log_backup_count): if log_file: from logging import Formatter from logging.handlers import RotatingFileHandler handler = RotatingFileHandler(log_file, maxBytes=max_log_bytes, backupCount=log_backup_count) handler.setLevel(log_level) handler.setFormatter(Formatter( fmt='%(asctime)s %(levelname)s %(name)s: %(message)s')) logging.getLogger().addHandler(handler) def get_app(root_dir, *, cache_key='prod', serve_admin=False, log_file=None, log_level=logging.INFO, log_backup_count=0, max_log_bytes=4096): _setup_logging(log_file, log_level, max_log_bytes, log_backup_count) app = get_piecrust_server(root_dir, serve_site=True, serve_admin=serve_admin, cache_key=cache_key) return app def get_admin_app(root_dir, *, cache_key='prod', log_file=None, log_level=logging.INFO, log_backup_count=0, max_log_bytes=4096): _setup_logging(log_file, log_level, max_log_bytes, log_backup_count) app = get_piecrust_server(root_dir, serve_site=False, serve_admin=True, cache_key=cache_key) return app