From 0392d25464a361c6b4114806f33e0374c1c78200 Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Mon, 11 Nov 2019 14:20:44 +0100 Subject: [PATCH] Hups --- app/corpora/events.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/app/corpora/events.py b/app/corpora/events.py index e33d275e..601cd654 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -7,7 +7,15 @@ from .CQiWrapper.CQiWrapper import CQiWrapper import logging +''' +' A dictionary containing lists of with corpus ids associated Socket.IO session +' ids (sid). {: [, ...], ...} +''' analysis_sessions = {} +''' +' A dictionary containing Socket.IO session id - CQi client pairs. +' {: CQi client, ...} +''' analysis_clients = {} @@ -26,7 +34,13 @@ def init_corpus_analysis(corpus_id): def recv_query(message): logger = logging.getLogger(__name__) logger.warning(message) - # analysis_client = analysis_clients[request.sid] + analysis_client = analysis_clients[request.sid] + corpus_name = 'CORPUS' + result_subcorpus_name = 'Query-results' # should be set by the user somehow + query = message['query'] + analysis_client.create_attribute_strings(corpus_name) + analysis_client.query_subcorpus(corpus_name, result_subcorpus_name, query) + analysis_client.show_results(corpus_name) def observe_corpus_analysis_connection(app, corpus_id, session_id): @@ -40,18 +54,16 @@ def observe_corpus_analysis_connection(app, corpus_id, session_id): password='opaque', port=4877, username='opaque') analysis_client.connect() - analysis_clients['session_id'] = analysis_client - corpus_name = 'CORPUS' - result_subcorpus_name = 'Query-results' # should be set by the user somehow - query = '"and";' - analysis_client.create_attribute_strings(corpus_name) - logger.warning('Log after create_attribute_strings.') - analysis_client.query_subcorpus(corpus_name, result_subcorpus_name, query) - logger.warning('Log after query_subcorpus.') - analysis_client.show_results(corpus_name) + analysis_clients[session_id] = analysis_client while session_id in connected_sessions: - logger.warning(analysis_client.ctrl_ping()) - socketio.sleep(3) + try: + analysis_client.ctrl_ping() + except Exception as err: + logger.warning('[Exception]: {}'.format(err)) + break + else: + socketio.sleep(3) + analysis_client.disconnect() analysis_clients.pop(session_id, None) analysis_sessions[str(corpus_id)].remove(session_id) if not analysis_sessions[str(corpus_id)]: