Skip to content

Commit

Permalink
feat: write connection file (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: benlubas <benmlubas@gmail.com>
  • Loading branch information
lkhphuc and benlubas committed Mar 30, 2024
1 parent 2fffc76 commit 5bc04c9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions rplugin/python3/molten/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def __init__(self, nvim: Nvim, kernel_name: str, kernel_id: str, options: Molten
jupyter_client.blocking.client.BlockingKernelClient,
)
self.kernel_client.start_channels()
self.kernel_client.connection_file = (
f"{self.kernel_client.data_dir}/runtime/kernel-{self.kernel_manager.kernel_id}.json"
)
self.kernel_client.write_connection_file()
else:
kernel_file = kernel_name
self.external_kernel = True
Expand Down Expand Up @@ -85,6 +89,7 @@ def deinit(self) -> None:
os.remove(path)

if self.external_kernel is False:
self.kernel_client.cleanup_connection_file()
self.kernel_client.shutdown()

def interrupt(self) -> None:
Expand Down Expand Up @@ -229,14 +234,11 @@ def tick(self, output: Optional[Output]) -> bool:
return did_stuff

def tick_input(self):
""" Tick to check input_requests """
"""Tick to check input_requests"""
if not self.is_ready:
return

assert isinstance(
self.kernel_client,
jupyter_client.blocking.client.BlockingKernelClient
)
assert isinstance(self.kernel_client, jupyter_client.blocking.client.BlockingKernelClient)

try:
msg = self.kernel_client.get_stdin_msg(timeout=0)
Expand All @@ -246,8 +248,9 @@ def tick_input(self):
pass

def take_input(self, msg):
if msg['msg_type'] == "input_request":
self.nvim.lua._prompt_stdin(self.kernel_id, msg['content']['prompt'])
if msg["msg_type"] == "input_request":
self.nvim.lua._prompt_stdin(self.kernel_id, msg["content"]["prompt"])


def get_available_kernels() -> List[str]:
return list(jupyter_client.kernelspec.find_kernel_specs().keys()) # type: ignore

0 comments on commit 5bc04c9

Please sign in to comment.