From 4556a52ffcb24822cd3f92aa3871ec4cd167e50d Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Mon, 30 Mar 2020 09:01:40 +0200 Subject: [PATCH] Abort transmission after disconnect --- app/corpora/pj_events.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/corpora/pj_events.py b/app/corpora/pj_events.py index 9b407eef..ac45cb40 100644 --- a/app/corpora/pj_events.py +++ b/app/corpora/pj_events.py @@ -24,10 +24,6 @@ pj_corpus_analysis_clients = {} @socketio.on('pj_corpus_analysis_init') @socketio_login_required def pj_init_corpus_analysis(corpus_id): - logger.warning( - '[{}] User {} > pj_corpus_analysis_init({})'.format(request.sid, - current_user.id, - corpus_id)) socketio.start_background_task(pj_corpus_analysis_session_handler, current_app._get_current_object(), corpus_id, current_user.id, request.sid) @@ -36,10 +32,6 @@ def pj_init_corpus_analysis(corpus_id): @socketio.on('pj_corpus_analysis_query') @socketio_login_required def pj_corpus_analysis_query(query): - logger.warning( - '[{}] User {} > pj_corpus_analysis_query({})'.format(request.sid, - current_user.id, - query)) client = pj_corpus_analysis_clients.get(request.sid) if client is None: response = {'code': 404, 'desc': 'No client found for this session', @@ -84,6 +76,7 @@ def pj_corpus_analysis_query(query): client.status = 'running' while chunk_start <= results.size: logger.warning(client.status) + print(client.status) if client.status == 'abort': break chunk = results.export(context=context, cutoff=chunk_size, @@ -145,6 +138,10 @@ def pj_corpus_analysis_session_handler(app, corpus_id, user_id, session_id): while session_id in connected_sessions: socketio.sleep(3) ''' Teardown analysis session ''' + if client.status == 'running': + client.status = 'abort' + while client.status != 'ready': + socketio.sleep(0.1) try: client.disconnect() except cqi.errors.CQiException: