Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an error if the file is erased while following #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Davd96
Copy link

@Davd96 Davd96 commented Jun 15, 2018

Actually if the file is deleted while pytailer is listening it dont raise any error and not restart reading in case the file is created again. So the thread is completely blocked.

@@ -159,6 +160,8 @@ def follow(self, delay=1.0):
trailing = True

while 1:
if not os.path.exists(os.path.realpath(self.file.name)): #Check if the file still exists
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.file may be a stream instead of a file with a name. So self.file.name might result in an attribute error. There are a couple of ways I can think of to handle this:

  1. If getattr(self.file, "name"), then assume it's a file and check for existence. However, this could be an expensive call on a long file since it will cause an extra disk read for every single line.
  2. Do a non-blocking readline and only yield something was read. This might be able to be done with select. I'm not certain how it will react if the file disappears. This will be a little more complex and might involve some more refactoring, but it should result in the best experience.

I'm inclined to choose option 2. Since you opened this pull request 5 years ago, you probably don't care anymore 😅. I'll see about fixing this. Thanks for the submission!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants