-
-
Notifications
You must be signed in to change notification settings - Fork 454
Use system temp directory for temporary HTML files #1296
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -457,7 +457,7 @@ def to_html( | |
| if not os.path.exists(out_dir): | ||
| os.makedirs(out_dir) | ||
| else: | ||
| outfile = os.path.abspath(common.random_string() + ".html") | ||
| outfile = common.temp_file_path(".html") | ||
| save = False | ||
|
|
||
|
Comment on lines
459
to
462
|
||
| output = widgets.Output() | ||
|
|
@@ -469,11 +469,13 @@ def to_html( | |
| with open(outfile) as f: | ||
| lines = f.readlines() | ||
| out_html = "".join(lines) | ||
| os.remove(outfile) | ||
| return out_html | ||
|
|
||
| except Exception as e: | ||
| raise Exception(e) | ||
| finally: | ||
| if not save and os.path.exists(outfile): | ||
| os.remove(outfile) | ||
|
|
||
| def to_streamlit( | ||
| self, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2657,7 +2657,7 @@ def to_html( | |
| if not os.path.exists(out_dir): | ||
| os.makedirs(out_dir) | ||
| else: | ||
| outfile = os.path.abspath(common.random_string() + ".html") | ||
| outfile = common.temp_file_path(".html") | ||
| save = False | ||
|
Comment on lines
+2660
to
2661
|
||
|
|
||
| if add_layer_control and self.layer_control is None: | ||
|
|
@@ -2697,11 +2697,13 @@ def to_html( | |
| with open(outfile) as f: | ||
| lines = f.readlines() | ||
| out_html = "".join(lines) | ||
| os.remove(outfile) | ||
| return out_html | ||
|
|
||
| except Exception as e: | ||
| raise Exception(e) | ||
| finally: | ||
| if not save and os.path.exists(outfile): | ||
| os.remove(outfile) | ||
|
|
||
| def to_image( | ||
| self, outfile: Optional[str] = None, monitor: Optional[int] = 1 | ||
|
|
||
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
outfileis auto-generated viatemp_file_path()(i.e.,save=False), the temp file is only deleted on the happy path. Ifembed_minimal_html()/file read fails, the temp file can be left behind in the system temp dir. Consider wrapping file generation/read intry/finallyso cleanup always happens when the outfile is implicitly created.