Skip to content

Commit 35ea94f

Browse files
tchatonthomas
andauthored
Optimize loading time for chunks to be there (#19109)
Co-authored-by: thomas <[email protected]>
1 parent e7d7399 commit 35ea94f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/lightning/app/utilities/logs_socket_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def create_lightning_logs_socket(
3333
project_id: str,
3434
app_id: str,
3535
component: str,
36-
on_message_callback: Callable[[WebSocketApp, str], None],
37-
on_error_callback: Optional[Callable[[Exception, str], None]] = None,
36+
on_message_callback: Callable,
37+
on_error_callback: Optional[Callable] = None,
3838
) -> WebSocketApp:
3939
"""Creates and returns WebSocketApp to listen to lightning app logs.
4040

src/lightning/data/streaming/item_loader.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,16 @@ def load_item_from_chunk(self, index: int, chunk_index: int, chunk_filepath: str
7474
del self._chunk_filepaths[chunk_filepath]
7575

7676
if chunk_filepath not in self._chunk_filepaths:
77-
while not os.path.exists(chunk_filepath):
77+
first_exists = exists = os.path.exists(chunk_filepath)
78+
79+
while not exists:
7880
sleep(0.01)
81+
exists = os.path.exists(chunk_filepath)
7982

8083
# Wait to avoid any corruption when the file appears
81-
sleep(0.01)
84+
if not first_exists:
85+
sleep(0.001)
86+
8287
self._chunk_filepaths[chunk_filepath] = True
8388

8489
with open(chunk_filepath, "rb", 0) as fp:
@@ -146,11 +151,16 @@ def load_item_from_chunk(self, index: int, chunk_index: int, chunk_filepath: str
146151
del self._chunk_filepaths[chunk_filepath]
147152

148153
if chunk_filepath not in self._chunk_filepaths:
149-
while not os.path.exists(chunk_filepath):
154+
first_exists = exists = os.path.exists(chunk_filepath)
155+
156+
while not exists:
150157
sleep(0.01)
158+
exists = os.path.exists(chunk_filepath)
151159

152160
# Wait to avoid any corruption when the file appears
153-
sleep(0.01)
161+
if not first_exists:
162+
sleep(0.001)
163+
154164
self._chunk_filepaths[chunk_filepath] = True
155165

156166
if chunk_index not in self._mmaps:

0 commit comments

Comments
 (0)