Abort transmission after disconnect

This commit is contained in:
Patrick Jentsch 2020-03-30 09:01:40 +02:00
parent 0be0e12aee
commit 4556a52ffc

View File

@ -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: