Raise an error if the file is erased while following#14
Open
Davd96 wants to merge 4 commits intosix8:masterfrom
Open
Raise an error if the file is erased while following#14Davd96 wants to merge 4 commits intosix8:masterfrom
Davd96 wants to merge 4 commits intosix8:masterfrom
Conversation
six8
reviewed
Apr 14, 2023
| trailing = True | ||
|
|
||
| while 1: | ||
| if not os.path.exists(os.path.realpath(self.file.name)): #Check if the file still exists |
Owner
There was a problem hiding this comment.
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:
- 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. - Do a non-blocking readline and only
yieldsomething 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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.