png rendering in a separate thread
This commit is contained in:
parent
18f51475ce
commit
01a321c202
1 changed files with 11 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ import logging
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
from gevent.threadpool import ThreadPool
|
||||||
from flask import render_template, send_file, make_response
|
from flask import render_template, send_file, make_response
|
||||||
|
|
||||||
import fmt.png
|
import fmt.png
|
||||||
|
|
@ -36,6 +37,8 @@ logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format='%(asctime)s %
|
||||||
|
|
||||||
LIMITS = Limits(whitelist=[MY_EXTERNAL_IP], limits=QUERY_LIMITS)
|
LIMITS = Limits(whitelist=[MY_EXTERNAL_IP], limits=QUERY_LIMITS)
|
||||||
|
|
||||||
|
TASKS = ThreadPool(25)
|
||||||
|
|
||||||
def show_text_file(name, lang):
|
def show_text_file(name, lang):
|
||||||
"""
|
"""
|
||||||
show static file `name` for `lang`
|
show static file `name` for `lang`
|
||||||
|
|
@ -212,8 +215,14 @@ def _response(parsed_query, query, fast_mode=False):
|
||||||
output = get_wetter(parsed_query)
|
output = get_wetter(parsed_query)
|
||||||
|
|
||||||
if parsed_query.get('png_filename'):
|
if parsed_query.get('png_filename'):
|
||||||
output = fmt.png.render_ansi(
|
# originally it was just a usual function call,
|
||||||
output, options=parsed_query)
|
# but it was a blocking call, so it was moved
|
||||||
|
# to separate threads:
|
||||||
|
#
|
||||||
|
# output = fmt.png.render_ansi(
|
||||||
|
# output, options=parsed_query)
|
||||||
|
result = TASKS.spawn(fmt.png.render_ansi, output, options=parsed_query)
|
||||||
|
output = result.get()
|
||||||
else:
|
else:
|
||||||
if query.get('days', '3') != '0' \
|
if query.get('days', '3') != '0' \
|
||||||
and not query.get('no-follow-line') \
|
and not query.get('no-follow-line') \
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue