Skip to content

Commit 9833b19

Browse files
Add proxy app to manager upon starting
We also check if proxy is "running" and if it is not, we remove proc object to restart the proxy. This way proxy will be restarted only when user does it via lancher.
1 parent d0faa17 commit 9833b19

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

jupyter_server_proxy/handlers.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .unixsock import UnixResolver
2424
from .utils import call_with_asked_args
2525
from .websocket import WebSocketHandlerMixin, pingable_ws_connect
26+
from .manager import manager
2627

2728

2829
class RewritableResponse(HasTraits):
@@ -800,9 +801,17 @@ async def ensure_process(self):
800801
# Invariant here should be: when lock isn't being held, either 'proc' is in state &
801802
# running, or not.
802803
async with self.state["proc_lock"]:
804+
805+
# If the server process is terminated via Runningsessions or killed
806+
# outside of jsp, we should be able to restart the process. If
807+
# process is not in running stated, remove proc object and restart
808+
# the process
809+
if 'proc' in self.state:
810+
if not self.state['proc'].running:
811+
del self.state['proc']
812+
803813
if "proc" not in self.state:
804814
# FIXME: Prevent races here
805-
# FIXME: Handle graceful exits of spawned processes here
806815

807816
# When command option isn't truthy, it means its a process not
808817
# to be managed/started by jupyter-server-proxy. This means we
@@ -836,6 +845,10 @@ async def ensure_process(self):
836845
if not is_ready:
837846
await proc.kill()
838847
raise web.HTTPError(500, f"could not start {self.name} in time")
848+
849+
# If process started succesfully, add it to manager
850+
# Add the server proxy app to manager
851+
await manager.add_server_proxy_app(self.name, self.base_url, cmd, self.port, proc)
839852
except:
840853
# Make sure we remove proc from state in any error condition
841854
del self.state["proc"]

0 commit comments

Comments
 (0)