Skip to content

Commit c755119

Browse files
committed
lock watcher
1 parent c760c40 commit c755119

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/toolong/poll_watcher.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ def run(self) -> None:
1717
while not self._exit_event.is_set():
1818
successful_read = False
1919
for fileno, watched_file in self._file_descriptors.items():
20-
try:
21-
position = lseek(fileno, 0, SEEK_CUR)
22-
if chunk := read(fileno, chunk_size):
23-
successful_read = True
24-
breaks = scan_chunk(chunk, position)
25-
watched_file.callback(position + len(chunk), breaks)
26-
position += len(chunk)
27-
except Exception as error:
28-
watched_file.error_callback(error)
29-
self._file_descriptors.pop(fileno, None)
30-
break
20+
with watched_file._lock:
21+
try:
22+
position = lseek(fileno, 0, SEEK_CUR)
23+
if chunk := read(fileno, chunk_size):
24+
successful_read = True
25+
breaks = scan_chunk(chunk, position)
26+
watched_file.callback(position + len(chunk), breaks)
27+
position += len(chunk)
28+
except Exception as error:
29+
watched_file.error_callback(error)
30+
self._file_descriptors.pop(fileno, None)
31+
break
3132
else:
3233
if not successful_read:
3334
time.sleep(0.05)

0 commit comments

Comments
 (0)