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

Win Support for LocalProcessProxy #1396

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 26 additions & 1 deletion enterprise_gateway/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,32 @@ async def post(self):
raise tornado.web.HTTPError(400)

# Transfer inherited environment variables from current process
env = {key: value for key, value in os.environ.items() if key in self.inherited_envs}
if os.name == "nt":
# We need to ensure we pass all needed environment variables to the kernel
# Users can use inherited_envs to add custom envrioment variables,
# and we ensure PATH, SYSTEMROOT, TEMP, USERPROFILE, WINDIR, COMSPEC, APPDATA, LOCALAPPDATA, PROGRAMDATA and PROGRAMFILES are included
# this allows a more out-of-the-box experience for users
required_envs: set[str] = {
"PATH",
"SYSTEMROOT",
"TEMP",
"USERPROFILE",
"WINDIR",
"COMSPEC",
"APPDATA",
"LOCALAPPDATA",
"PROGRAMDATA",
"PROGRAMFILES",
}
env = {
key: value
for key, value in os.environ.items()
if key in self.inherited_envs or key in required_envs
}
else:
env = {
key: value for key, value in os.environ.items() if key in self.inherited_envs
}

# Allow all KERNEL_* envs and those specified in client_envs and set from client. If this EG
# instance is configured to accept all envs in the payload (i.e., client_envs == '*'), go ahead
Expand Down
6 changes: 6 additions & 0 deletions enterprise_gateway/services/processproxies/processproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ def __init__(self, kernel_manager: RemoteKernelManager, proxy_config: dict): #
"""Initialize the proxy."""
super().__init__(kernel_manager, proxy_config)
kernel_manager.ip = localinterfaces.LOCALHOST
if os.name == "nt":
self.win32_interrupt_event = None

async def launch_process(
self, kernel_cmd: str, **kwargs: dict[str, Any] | None
Expand All @@ -1059,6 +1061,10 @@ async def launch_process(
except OSError:
pass
self.ip = local_ip
if (
os.name == "nt"
): # if operating system is Windows then link the win32_interrupt_event from the kernel
self.win32_interrupt_event = self.local_proc.win32_interrupt_event
self.log.info(
"Local kernel launched on '{}', pid: {}, pgid: {}, KernelID: {}, cmd: '{}'".format(
self.ip, self.pid, self.pgid, self.kernel_id, kernel_cmd
Expand Down
Loading