-
Notifications
You must be signed in to change notification settings - Fork 4k
Server: store SessionInfo by id #1056
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
Server: store SessionInfo by id #1056
Conversation
- IDs are strings - active voice in function docstrings
monchier
left a comment
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.
I started a review, but wants to spend some more time. @tconkling I am assuming you are not going to land this today. Let me know if in a hurry.
| """Create a mock ReportSession. Each mocked instance will have | ||
| its own unique ID.""" |
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.
At some point we said to use plain # for descriptions of private methods.
| """Mock the Server's ReportSession import. We don't want | ||
| actual sessions to be instantiated, or scripts to be run. | ||
| """ |
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.
At some point we said to use plain # for descriptions of private methods.
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.
Whoa, really? I strongly disagree with, and am confused by, that. For example, my IDE auto-parses docstrings to provide inline context.
What do we gain by having two different methods for documenting methods?
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.
I think """ """ are picked up by documentation tools.
I don't have a strong opinion and I won't block this PR for this. @tvst?
monchier
left a comment
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.
Just minor notes.
| assert len(self._session_info_by_id) == 1 | ||
| LOGGER.debug("Reusing preheated context for ws %s", ws) | ||
| session = self._session_info_by_id[PREHEATED_REPORT_SESSION].session | ||
| del self._session_info_by_id[PREHEATED_REPORT_SESSION] |
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.
I wonder if all this could be put in a function. It seems this is a get_preheaded_report_session.
| assert session.id not in self._session_info_by_id, ( | ||
| "session.id '%s' registered multiple times!" % session.id | ||
| ) | ||
| self._session_info_by_id[session.id] = SessionInfo(ws, session) |
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.
Same here. Could this be get_session_info? So that we wrap the check in it/
| session_info = self._session_info_by_id[session_id] | ||
| del self._session_info_by_id[session_id] |
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.
Another function? BTW, fine if you think this is just a couple of extra lines and it is more readable.
* develop: (30 commits) [Screencast] Fixing countdown bug (streamlit#1082) Release 0.56.0 (streamlit#1101) Fix bug where icon assets were missing from "make install" (streamlit#1100) Clean signatures of wrapped DeltaGenerator methods (streamlit#1099) Using widgetId as the key when rendering elements (streamlit#1102) Pass --skip-lock to pipenv under pipenv-install Makefile target. (streamlit#1093) Allow wider range of int-like types in NumberInput (streamlit#1087) Fix missing caching URL (streamlit#1094) Version 0.55.1 (just pointing to new docs) (streamlit#1089) Retire python-3.7.4 CircleCI project. (streamlit#1086) Handle different Caching error messages (streamlit#1068) Fix an incomplete copy for a dict that's then modified. (streamlit#1078) Fix indentation error in fad994c. (streamlit#1084) Widgets unit tests (streamlit#1077) [mypy] First phase of work on testing Python type annotations. (streamlit#1079) Add CircleCI jobs to run the oldest and newest Python versions we support. (streamlit#1053) Improve docs (streamlit#1075) Adding CORS to troubleshooting guide. (streamlit#1001) Fix for the CORS check (streamlit#965) Advanced caching updates feb (streamlit#1040) ...
# By Nahuel Emiliano Rosso Fandiño (1) and others # Via GitHub * develop: Show warning to user and use skipkeys=True if json.dumps causes TypeError (streamlit#1112) Server: store SessionInfo by id (streamlit#1056) [Screencast] Fixing countdown bug (streamlit#1082) # Conflicts: # lib/streamlit/server/Server.py
* develop: (53 commits) Update plotly.js to 1.52 (streamlit#1119) Add tooltip in Altair/Vega-lite docstring code (streamlit#1092) Ability to bind to a server address with server.address config option (streamlit#1107) [mypy] Enable check_untyped_defs throughout the codebase. (streamlit#1110) st.map: set "radiusMinPixels" to 3 (streamlit#1113) st.plotly_chart docs incorrectly refer to Altair (streamlit#1118) Fix BytesIO and numpy array data sources for audio/video (streamlit#1116) Show warning to user and use skipkeys=True if json.dumps causes TypeError (streamlit#1112) Server: store SessionInfo by id (streamlit#1056) [Screencast] Fixing countdown bug (streamlit#1082) Release 0.56.0 (streamlit#1101) Fix bug where icon assets were missing from "make install" (streamlit#1100) Clean signatures of wrapped DeltaGenerator methods (streamlit#1099) Using widgetId as the key when rendering elements (streamlit#1102) Pass --skip-lock to pipenv under pipenv-install Makefile target. (streamlit#1093) Allow wider range of int-like types in NumberInput (streamlit#1087) Fix missing caching URL (streamlit#1094) Version 0.55.1 (just pointing to new docs) (streamlit#1089) Retire python-3.7.4 CircleCI project. (streamlit#1086) Handle different Caching error messages (streamlit#1068) ...
This is a prelude commit to incoming FileUploader-related changes.
Motivation
Each
ReportSessionhas a unique ID, but the server doesn't currently have a good way to retrieve aReportSessionby its ID. Instead, the Server currently maintains a dictionary that maps WebsocketHandlers -> ReportSessions.This patch essentially just changes that dictionary to be a mapping of SessionID -> ReportSession, which will enable other HTTP endpoints to refer to running
ReportSessions by ID. The upcoming FileUploader HTTP endpoint will use this to add an uploaded file to its associated ReportSession.Details
ReportSession.idis now a str instead of an int. (This isn't strictly necessary, but it simplifies some things, and also allows us to easily make report session ID unguessable in the future - if this is a concern - by using a UUID.)Server._session_infosis nowServer._session_info_by_id, and stores a mapping of string ID toSessionInfo.SessionInfonow holds its associated WebsocketHandler in addition to the ReportSession.