Skip to content

Commit 1ed888e

Browse files
committed
Sorting outputs by output index, simplified length check
1 parent 3640e7b commit 1ed888e

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

jupyter_server_documents/outputs/manager.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,30 @@ def get_outputs(self, file_id, cell_id):
5757

5858
outputs = []
5959

60-
# Collect .output files with their modification times
6160
output_files = [
62-
(f, os.path.getmtime(f))
61+
(f, int(f.stem))
6362
for f in path.glob("*.output")
6463
]
65-
66-
# Sort .output files by modification time
6764
output_files.sort(key=lambda x: x[1])
65+
output_files = output_files[:self.stream_limit]
66+
has_more_files = len(output_files) >= self.stream_limit
6867

69-
# Load sorted .output files
68+
outputs = []
7069
for file_path, _ in output_files:
71-
if len(outputs) >= self.stream_limit:
72-
url = f"/api/outputs/{file_id}/{cell_id}/stream"
73-
placeholder = {
74-
"output_type": "display_data",
75-
"data": {
76-
'text/html': f'<a href="{url}">Click this link to see the full stream output</a>'
77-
}
78-
}
79-
outputs.append(json.dumps(placeholder))
80-
break
8170
with open(file_path, "r", encoding="utf-8") as f:
8271
output = f.read()
8372
outputs.append(output)
8473

74+
if has_more_files:
75+
url = f"/api/outputs/{file_id}/{cell_id}/stream"
76+
placeholder = {
77+
"output_type": "display_data",
78+
"data": {
79+
'text/html': f'<a href="{url}">Click this link to see the full stream output</a>'
80+
}
81+
}
82+
outputs.append(json.dumps(placeholder))
83+
8584
return outputs
8685

8786

0 commit comments

Comments
 (0)