-
Notifications
You must be signed in to change notification settings - Fork 116
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
set summarizer write to tempfile #330
Conversation
Signed-off-by: Michael Clifford <[email protected]>
Similar issue encountered in: #307 but this solves it a better way |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
There is security risks in writing to tmp, can you use a tmpfile name rather then a hard coded file name? |
Signed-off-by: Michael Clifford <[email protected]>
Thanks @rhatdan Changed it to use a tempfile instead. |
@@ -49,12 +50,12 @@ def read_file(file): | |||
file_type = file.type | |||
|
|||
if file_type == "application/pdf": | |||
with open(file.name, "wb") as f: | |||
temp = tempfile.NamedTemporaryFile() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still need to remove this when you are done with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tested it the tempfile deleted after the file was no longer being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this some magic in Python?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the [tempfile module](http://docs.python.org/2/library/tempfile.html); it creates temporary files that auto-delete.
From the [tempfile.NamedTemporaryFile() documentation](http://docs.python.org/2/library/tempfile.html#tempfile.NamedTemporaryFile):
If delete is true (the default), the file is deleted as soon as it is closed.
Cool
LGTM |
Follow up to #302
Noticed summarizer was having write issues in container. Using the
/tmp/
directory should address it.