Skip to content

Commit

Permalink
Handle inotify related exception
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloLec committed Oct 2, 2021
1 parent 70595a0 commit 564c923
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions livelog/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def _parse_args():
if args.file is not None:
file = Path(args.file)
else:
file = Path(
"/tmp/livelog.log"
file = (
Path("/tmp/livelog.log")
if system() == "Darwin"
else Path(gettempdir()) / "livelog.log"
)
Expand Down
22 changes: 16 additions & 6 deletions livelog/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def file_exists(self):
bool: File exists
"""

return self.file.isfile()
return self.file.is_file()

def print_output(self):
"""Drive the printing process by getting new lines, filtering log
Expand Down Expand Up @@ -177,6 +177,13 @@ def on_modified(self, *args, **kwargs):

self.print_output()

def loop_without_event(self):
"""If inotify instance limit reached, loop without watching file."""

while True:
self.print_output()
sleep(1)


def start_reader(file: str, level: str, nocolors: bool):
"""Start reader process.
Expand All @@ -190,8 +197,11 @@ def start_reader(file: str, level: str, nocolors: bool):
event_handler = Reader(file=file, level=level, nocolors=nocolors)
observer = Observer()
observer.schedule(event_handler, file, recursive=True)
observer.start()

input("")
observer.stop()
observer.join()
try:
observer.start()
input("")
observer.stop()
observer.join()
except OSError:
# Handle "OSError: [Errno 24] inotify instance limit reached" exception
event_handler.loop_without_event()

0 comments on commit 564c923

Please sign in to comment.