Skip to content

Expire media files when ReportSession expires#1128

Merged
nthmost merged 40 commits intostreamlit:developfrom
nthmost:expire_media_files
Mar 5, 2020
Merged

Expire media files when ReportSession expires#1128
nthmost merged 40 commits intostreamlit:developfrom
nthmost:expire_media_files

Conversation

@nthmost
Copy link
Copy Markdown
Contributor

@nthmost nthmost commented Feb 21, 2020

Issue: #415

Description: Our new MediaFileManager stores files for serving via HTTP, but doesn't have any limits on how long those files will be kept.

This PR introduces memory management for the MediaFileManager in the form of tracking which ReportSession is using which files. When all references to the files being used by different ReportSession IDs run out, those files are removed from the cache.

To accomplish this, some piping of the ReportSession ID is done in ScriptRunner and ReportThread using the report_session_id attribute / keyword.


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@nthmost nthmost changed the title Expire media files Expire media files when ReportSession expires Feb 27, 2020
@nthmost nthmost marked this pull request as ready for review February 27, 2020 01:07
@nthmost nthmost requested a review from a team as a code owner February 27, 2020 01:07
@tvst tvst added the WIP label Feb 27, 2020
Copy link
Copy Markdown
Contributor

@tvst tvst left a comment

Choose a reason for hiding this comment

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

I think you can fix your python 3.5 integration test issue by replacing MediaFileManager's _get_session_id() with this version:

def _get_session_id():
    """Semantic wrapper to retrieve current ReportSession ID."""
    ctx = get_report_ctx()
    if ctx is None:
        # This is only None when running "python myscript.py" rather than
        # "streamlit run myscript.py". In which case the session ID doesn't
        # matter and can just be a constant, as there's only ever "session".
        return "dontcare"
    else:
        return ctx.report_session_id

Copy link
Copy Markdown
Contributor

@tvst tvst left a comment

Choose a reason for hiding this comment

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

Approved! But please address the comments before merging.



# Avoid circular dependencies in Python 2
# Needed to avoid circular dependencies.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So this is still needed in Python 3?

Copy link
Copy Markdown
Contributor Author

@nthmost nthmost Mar 4, 2020

Choose a reason for hiding this comment

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

When I take it out, the tests break. However, streamlit run x.py works without it...

@nthmost nthmost merged commit 52633b5 into streamlit:develop Mar 5, 2020
@nthmost nthmost deleted the expire_media_files branch March 5, 2020 23:12
tconkling added a commit to tconkling/streamlit that referenced this pull request Mar 9, 2020
* develop:
  Unpin python-dateutil package version (streamlit#1153)
  Pypi nightly builds (streamlit#1171)
  Adding custom filterOptions function to SelectBox (streamlit#1182)
  Expire media files when ReportSession expires (streamlit#1128)
  1159/use_container_width (streamlit#1174)
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