Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lightning_app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed the endpoint info tab not showing up in `AutoScaler` UI ([#16128](https://github.com/Lightning-AI/lightning/pull/16128))


- Fixed an issue where an exception would be raised in the logs when using a recent version of streamlit ([#16139](https://github.com/Lightning-AI/lightning/pull/16139))


## [1.8.5] - 2022-12-15

### Added
Expand Down
40 changes: 28 additions & 12 deletions src/lightning_app/utilities/app_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,22 @@ def render_non_authorized(self):


def target_fn():
from streamlit.server.server import Server
try:
# streamlit >= 1.14.0
from streamlit import runtime

get_instance = runtime.get_instance
exists = runtime.exists()
except ImportError:
# Older versions
from streamlit.server.server import Server

get_instance = Server.get_current
exists = bool(Server._singleton)

async def update_fn():
server = Server.get_current()
sessions = list(server._session_info_by_id.values())
runtime_instance = get_instance()
sessions = list(runtime_instance._session_info_by_id.values())
url = (
"localhost:8080"
if "LIGHTNING_APP_STATE_URL" in os.environ
Expand All @@ -198,15 +209,20 @@ async def update_fn():
last_updated = time.time()
async with websockets.connect(ws_url) as websocket:
while True:
_ = await websocket.recv()
while (time.time() - last_updated) < 1:
time.sleep(0.1)
for session in sessions:
session = session.session
session.request_rerun(session._client_state)
last_updated = time.time()

if Server._singleton:
try:
_ = await websocket.recv()

while (time.time() - last_updated) < 1:
time.sleep(0.1)
for session in sessions:
session = session.session
session.request_rerun(session._client_state)
last_updated = time.time()
except websockets.exceptions.ConnectionClosedOK:
# The websocket is not enabled
break

if exists:
asyncio.run(update_fn())


Expand Down