Implement logger in another way.

This commit is contained in:
Patrick Jentsch 2019-11-12 13:23:54 +01:00
parent 6459c9f064
commit 2bebd0256c
2 changed files with 11 additions and 10 deletions

View File

@ -4,9 +4,11 @@ from flask_login import LoginManager
from flask_mail import Mail
from flask_socketio import SocketIO
from flask_sqlalchemy import SQLAlchemy
import logging
db = SQLAlchemy()
logger = logging.getLogger(__name__)
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
mail = Mail()

View File

@ -1,11 +1,9 @@
from app import db, socketio
from app import db, logger, socketio
from app.events import connected_sessions
from app.models import Corpus
from flask import current_app, request
from flask_login import current_user, login_required
from .CQiWrapper.CQiWrapper import CQiWrapper
import logging
import json
'''
@ -40,24 +38,22 @@ def init_corpus_analysis(corpus_id):
@socketio.on('query_event')
@login_required
def recv_query(message):
logger = logging.getLogger(__name__)
logger.warning(message)
analysis_client = analysis_clients[request.sid]
corpus_name = 'CORPUS'
result_subcorpus_name = 'Query-results'
result_subcorpus_name = 'Query-results' # should be set by the user somehow
query = message['query']
analysis_client.set_corpus_name(corpus_name)
analysis_client.create_attribute_strings()
analysis_client.query_subcorpus(result_subcorpus_name, query)
results = analysis_client.show_results()
logger.warning('Vorher')
#results = analysis_client.show_results()
results = analysis_client.get_cpos_info([1995, 2000], analysis_client)
logger.warning('Nacher')
logger.warning('Query results: {}'.format(str(results)))
json_results = json.dumps(results)
logger.warning('JSON results are {}'.format(json_results))
socketio.emit('query_results', json_results)
def observe_corpus_analysis_connection(app, corpus_id, session_id):
logger = logging.getLogger(__name__)
with app.app_context():
corpus = Corpus.query.filter_by(id=corpus_id).first()
while corpus.status != 'analysing':
@ -70,6 +66,7 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
analysis_clients[session_id] = analysis_client
socketio.emit('init_corpus_analysis', 'Ready', room=session_id)
while session_id in connected_sessions:
'''
try:
analysis_client.ctrl_ping()
except Exception as err:
@ -77,6 +74,8 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id):
break
else:
socketio.sleep(3)
'''
socketio.sleep(3)
analysis_client.disconnect()
analysis_clients.pop(session_id, None)
analysis_sessions[str(corpus_id)].remove(session_id)