Skip to content

Commit 7b9cc9a

Browse files
committed
addressing @wasade review
1 parent 554bd63 commit 7b9cc9a

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

qiita_db/handlers/analysis.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from tornado import gen
1010
from tornado.web import HTTPError
11-
from tornado.iostream import StreamClosedError
1211
from json import dumps
1312

1413
import qiita_db as qdb
@@ -67,6 +66,7 @@ async def get(self, analysis_id):
6766
"""
6867
chunk_len = 1024 * 1024 * 1 # 1 MiB
6968

69+
respose = None
7070
with qdb.sql_connection.TRN:
7171
a = _get_analysis(analysis_id)
7272
mf_fp = qdb.util.get_filepath_information(
@@ -76,17 +76,19 @@ async def get(self, analysis_id):
7676
mf_fp, index='#SampleID')
7777
response = dumps(df.to_dict(orient='index'))
7878

79-
crange = range(chunk_len, len(response)+chunk_len, chunk_len)
80-
for i, (win) in enumerate(crange):
81-
chunk = response[i*chunk_len:win]
82-
try:
83-
self.write(chunk)
84-
await self.flush()
85-
except StreamClosedError:
86-
break
87-
finally:
88-
del chunk
89-
# pause the coroutine so other handlers can run
90-
await gen.sleep(0.000000001) # 1 nanosecond
91-
else:
92-
self.write(None)
79+
if respose is not None:
80+
crange = range(chunk_len, len(response)+chunk_len, chunk_len)
81+
for i, (win) in enumerate(crange):
82+
# sending the chunk and flushing
83+
chunk = response[i*chunk_len:win]
84+
self.write(chunk)
85+
await self.flush()
86+
87+
# cleaning chuck and pause the coroutine so other handlers
88+
# can run, note that this is required/important based on the
89+
# original implementation in https://bit.ly/3CPvyjd
90+
del chunk
91+
await gen.sleep(0.000000001) # 1 nanosecond
92+
93+
else:
94+
respose.write(None)

0 commit comments

Comments
 (0)