diff options
author | Keuin <[email protected]> | 2023-06-04 16:10:36 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-06-04 16:10:36 +0800 |
commit | c9e52fbed5d5d42e319e17945ed5ab8a59274552 (patch) | |
tree | cfa7ed01195df46c7feb8c38c094b95d1e3a3f43 | |
parent | 063e8fed7ee2b4f6c6d2adfc5f244f7d5cd5b9e2 (diff) |
bugfix: config load does not take effect
-rw-r--r-- | app.py | 34 | ||||
-rw-r--r-- | web.py | 31 |
2 files changed, 34 insertions, 31 deletions
@@ -0,0 +1,34 @@ +import argparse +import asyncio +import os + +import uvicorn +from uvicorn.loops.auto import auto_loop_setup + +import web + + +def setup_loop(): + if os.name == 'nt': + # use ProactorEventLoop to support async subprocess on Windows + print('Driving event loop with IOCP.') + loop = asyncio.ProactorEventLoop() + asyncio.set_event_loop(loop) + auto_loop_setup() + + +if __name__ == '__main__': + p = argparse.ArgumentParser(prog='utaten2tex') + p.add_argument('-l', '--host', default='127.0.0.1') + p.add_argument('-p', '--port', default='8080') + p.add_argument('-P', '--preview-pdf', action='store_true', default=False) + args = p.parse_args() + web.preview_pdf = args.preview_pdf + setup_loop() + uvicorn.run( + 'web:app', + host=args.host, + port=int(args.port), + log_level='info', + loop='none', # use custom loop initializer + ) @@ -1,12 +1,7 @@ -import argparse -import asyncio -import os import re -import uvicorn from fastapi import FastAPI, Response from fastapi.responses import FileResponse -from uvicorn.loops.auto import auto_loop_setup import htmlcache import texgen @@ -56,29 +51,3 @@ async def get_utaten_lyric_tex(item_id: str): @app.on_event("startup") async def startup_event(): pass - - -def setup_loop(): - if os.name == 'nt': - # use ProactorEventLoop to support async subprocess on Windows - print('Driving event loop with IOCP.') - loop = asyncio.ProactorEventLoop() - asyncio.set_event_loop(loop) - auto_loop_setup() - - -if __name__ == '__main__': - p = argparse.ArgumentParser(prog='utaten2tex') - p.add_argument('-l', '--host', default='127.0.0.1') - p.add_argument('-p', '--port', default='8080') - p.add_argument('-P', '--preview-pdf', action='store_true', default=False) - args = p.parse_args() - preview_pdf = args.preview_pdf - setup_loop() - uvicorn.run( - 'web:app', - host=args.host, - port=int(args.port), - log_level='info', - loop='none', # use custom loop initializer - ) |