diff options
author | morpheus65535 <[email protected]> | 2021-10-20 20:46:22 -0400 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2021-10-20 20:46:22 -0400 |
commit | 39fe3141d51b01479e7b585ad0b5ee5df1767226 (patch) | |
tree | 8f2617fbe98281498fd9617c5346a5bfdc841963 /libs/waitress/__init__.py | |
parent | 8b0b965c8f2bbeccf277892c617bfa602028bd8c (diff) | |
download | bazarr-39fe3141d51b01479e7b585ad0b5ee5df1767226.tar.gz bazarr-39fe3141d51b01479e7b585ad0b5ee5df1767226.zip |
Moved back from gevent to waitress web server. This should prevent UI disconnection occurring during heavy task like syncing subtitles.v1.0.1-beta.1
Diffstat (limited to 'libs/waitress/__init__.py')
-rw-r--r-- | libs/waitress/__init__.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libs/waitress/__init__.py b/libs/waitress/__init__.py new file mode 100644 index 000000000..bbb99da03 --- /dev/null +++ b/libs/waitress/__init__.py @@ -0,0 +1,46 @@ +import logging + +from waitress.server import create_server + + +def serve(app, **kw): + _server = kw.pop("_server", create_server) # test shim + _quiet = kw.pop("_quiet", False) # test shim + _profile = kw.pop("_profile", False) # test shim + if not _quiet: # pragma: no cover + # idempotent if logging has already been set up + logging.basicConfig() + server = _server(app, **kw) + if not _quiet: # pragma: no cover + server.print_listen("Serving on http://{}:{}") + if _profile: # pragma: no cover + profile("server.run()", globals(), locals(), (), False) + else: + server.run() + + +def serve_paste(app, global_conf, **kw): + serve(app, **kw) + return 0 + + +def profile(cmd, globals, locals, sort_order, callers): # pragma: no cover + # runs a command under the profiler and print profiling output at shutdown + import os + import profile + import pstats + import tempfile + + fd, fn = tempfile.mkstemp() + try: + profile.runctx(cmd, globals, locals, fn) + stats = pstats.Stats(fn) + stats.strip_dirs() + # calls,time,cumulative and cumulative,calls,time are useful + stats.sort_stats(*(sort_order or ("cumulative", "calls", "time"))) + if callers: + stats.print_callers(0.3) + else: + stats.print_stats(0.3) + finally: + os.remove(fn) |