|
23 | 23 | from .unixsock import UnixResolver
|
24 | 24 | from .utils import call_with_asked_args
|
25 | 25 | from .websocket import WebSocketHandlerMixin, pingable_ws_connect
|
| 26 | +from .manager import manager |
26 | 27 |
|
27 | 28 |
|
28 | 29 | class RewritableResponse(HasTraits):
|
@@ -800,9 +801,17 @@ async def ensure_process(self):
|
800 | 801 | # Invariant here should be: when lock isn't being held, either 'proc' is in state &
|
801 | 802 | # running, or not.
|
802 | 803 | 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 | + |
803 | 813 | if "proc" not in self.state:
|
804 | 814 | # FIXME: Prevent races here
|
805 |
| - # FIXME: Handle graceful exits of spawned processes here |
806 | 815 |
|
807 | 816 | # When command option isn't truthy, it means its a process not
|
808 | 817 | # to be managed/started by jupyter-server-proxy. This means we
|
@@ -836,6 +845,10 @@ async def ensure_process(self):
|
836 | 845 | if not is_ready:
|
837 | 846 | await proc.kill()
|
838 | 847 | 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) |
839 | 852 | except:
|
840 | 853 | # Make sure we remove proc from state in any error condition
|
841 | 854 | del self.state["proc"]
|
|
0 commit comments