Skip to content
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

Add state repr and server kill command #697

Merged
merged 4 commits into from
Oct 13, 2019
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
6 changes: 3 additions & 3 deletions panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import signal
import threading
import uuid

from functools import partial

Expand Down Expand Up @@ -77,10 +78,9 @@ def get_server(panel, port=0, websocket_origin=None, loop=None,
websocket_origin = [websocket_origin]
opts['allow_websocket_origin'] = websocket_origin

server_id = kwargs.pop('server_id', None)
server_id = kwargs.pop('server_id', uuid.uuid4().hex)
server = Server({'/': partial(panel._modify_doc, server_id)}, port=port, **opts)
if server_id:
state._servers[server_id] = (server, panel, [])
state._servers[server_id] = (server, panel, [])

if show:
def show_callback():
Expand Down
16 changes: 15 additions & 1 deletion panel/io/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,23 @@ class _state(param.Parameterized):
# An index of all currently active views
_views = {}

# An index of all curently active servers
# An index of all currently active servers
_servers = {}

def __repr__(self):
server_info = []
for server, panel, docs in self._servers.values():
server_info.append("{}:{:d} - {!r}".format(
server.address or "localhost", server.port, panel)
)
return "state(servers=\n {}\n)".format(",\n ".join(server_info))

def kill_all_servers(self):
"""Stop all servers and clear them from the current state."""
for server_id in self._servers:
self._servers[server_id][0].stop()
self._servers = {}

def _unblocked(self, doc):
thread = threading.current_thread()
thread_id = thread.ident if thread else None
Expand Down