Skip to content

Commit

Permalink
Made sure that Proxy._proxy_connection_is_registered(...) was called …
Browse files Browse the repository at this point in the history
…*inside* Proxy.replace_connection_and_queue(...) since the former was a precondition of the latter.
  • Loading branch information
treuille committed Nov 25, 2018
1 parent 1fcb6ab commit 66540ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
15 changes: 4 additions & 11 deletions lib/streamlit/proxy/BrowserWebSocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,10 @@ def do_loop(self):

try:
while self._is_open:
if not self._proxy.proxy_connection_is_registered(self._connection):
LOGGER.debug('The proxy connection for "%s" is not registered.',
self._report_name)
self._connection, self._queue = (
yield self._proxy.on_browser_waiting_for_proxy_conn(
self._report_name, self,
self._connection, self._queue))
LOGGER.debug('Got a new connection ("%s") : %s',
self._connection.name, self._connection)
LOGGER.debug('Got a new queue : "%s"', self._queue)

self._connection, self._queue = (
yield self._proxy.replace_connection_and_queue(
self._report_name, self,
self._connection, self._queue))
if not self._queue.is_closed():
yield self._queue.flush_queue(self)
elif not indicated_closed:
Expand Down
30 changes: 22 additions & 8 deletions lib/streamlit/proxy/Proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def schedule_potential_deregister_and_stop(self, connection):
"""

def potentially_unregister():
if not self.proxy_connection_is_registered(connection):
if not self._proxy_connection_is_registered(connection):
return

if not connection.can_be_deregistered():
Expand Down Expand Up @@ -225,7 +225,7 @@ def _deregister_proxy_connection(self, connection):
LOGGER.debug(f'Got rid of connection {connection.name}')
LOGGER.debug(f'Total connections left: {len(self._connections)}')

def proxy_connection_is_registered(self, connection):
def _proxy_connection_is_registered(self, connection):
"""Return true if this connection is registered to its name."""
return self._connections.get(connection.name, None) is connection

Expand Down Expand Up @@ -285,28 +285,42 @@ def on_browser_connection_closed(self, connection, queue): # noqa: D401
self._deregister_browser(connection, queue)

@gen.coroutine
def on_browser_waiting_for_proxy_conn( # noqa: D401
self, report_name, ws, old_connection, old_queue):
"""Called when a client detects it has no corresponding ProxyConnection.
def replace_connection_and_queue( # noqa: D401
self, report_name, ws, connection, queue):
"""Gets the most recent proxy connection and queue for this report_name.
BrowserWebSocket continuously calls this method in case a new client
connection was established, in which case the BrowserWebSocket should
switch to the new proxy connection and queue.
Parameters
----------
report_name : str
The name of the report the browser connection is for.
ws : BrowserWebSocket
The BrowserWebSocket instance that just got opened.
old_connection : ProxyConnection
connection : ProxyConnection
The connection object that just got closed.
old_queue : ReportQueue
queue : ReportQueue
The client queue corresponding to the closed connection.
Returns
-------
ProxyConnection
The newly registered proxy connection.
ReportQueue
The corresponding newly registered queue.
"""
self._deregister_browser(old_connection, old_queue)
# No need to change the connection or queue if the current one is still
# registered.
if self._proxy_connection_is_registered(connection):
raise gen.Return((connection, queue))

LOGGER.debug('The proxy connection for "%s" is not registered.',
report_name)

self._deregister_browser(connection, queue)
new_connection, new_queue = (
yield self._register_browser(report_name, ws))
raise gen.Return((new_connection, new_queue))
Expand Down
15 changes: 0 additions & 15 deletions tmp-rename-modules.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
**Note** This file will be deleted! Reviewers, please ignore! These are just notes fro me as I work on this renaming project.

---

# PR 3: Fixups

- first big fixup
- look this up and understand it better `on_browser_waiting_for_proxy_conn`
- `on_browser_waiting_for_proxy_conn(` -> `replace_connection_and_queue(`

- `Called when a client detects it has no corresponding ProxyConnection.` -> `Gets the most recent proxy connection and queue for this report_name. (BrowserWebSocket continuously calls this to in case a new client connection was established in which case the BrowserWebSocket should switch to the new proxy connection and queue.)`

- little cleanup:
- move `proxy_connection_is_registered` into `on_browser_waiting_for_proxy_conn`
- give it a better name in `BrowserWebSocket.do_loop`
- update doc string: `Gets the most recent proxy connection and queue for this report_name.`
- commit
- `STREAMLIT_ROOT_DIRECTORY` : make that a direct `util` thing `caching.py`

0 comments on commit 66540ee

Please sign in to comment.