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

#7617 - fix for passing context json as process parameter on windows #7623

Merged
merged 1 commit into from
Jul 2, 2018
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
3 changes: 2 additions & 1 deletion beakerx/beakerx/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,5 +619,6 @@ def get_context_session():
kernel = get_ipython().kernel
# if subkernel get session from extra start parameters
if len(kernel.parent.argv) == 3:
return json.loads(kernel.parent.argv[2])['contextId']
context_json = base64.b64decode(kernel.parent.argv[2]).decode('UTF-8')
return json.loads(context_json)['contextId']
return kernel.session.session
8 changes: 5 additions & 3 deletions beakerx/beakerx_magics/kernel_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from jupyter_client.manager import KernelManager
from ipykernel.zmqshell import ZMQInteractiveShell
import atexit
import base64
import json
import logging
import os
Expand All @@ -38,7 +39,7 @@ def __init__(self, shell):
def start(self, kernel_name):
self.km = KernelManager()
self.km.kernel_name = kernel_name
self.km.start_kernel(extra_arguments=[self._context_as_string()])
self.km.start_kernel(extra_arguments=[self._context_base64()])
atexit.register(self.stop_kernel)
self.kc = self.km.client()
self.kc.start_channels()
Expand Down Expand Up @@ -85,11 +86,12 @@ def pass_message(self, msg_raw):
# don't create the list of keys if debug messages aren't enabled
self.log.debug("Current comms: %s", list(self.comms.keys()))

def _context_as_string(self):
return json.dumps({
def _context_base64(self):
context_json = json.dumps({
'port': os.environ["BEAKERX_AUTOTRANSLATION_PORT"],
'contextId': get_ipython().kernel.session.session,
})
return base64.b64encode(context_json.encode('utf-8')).decode()


def comm_msg(stream, ident, msg):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import com.twosigma.beakerx.message.MessageSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import py4j.Base64;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Map;
Expand All @@ -44,7 +46,12 @@ public KernelConfigurationFile(final String[] args) {
}
this.config = getConfig(args[0]);
if (args.length == 2) {
String contextAsJson = args[1];
String contextAsJson = null;
try {
contextAsJson = new String(Base64.decode(args[1]), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
this.context = Optional.of(contextAsJson);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.twosigma.beakerx.message.Header;
import com.twosigma.beakerx.message.Message;
import org.apache.commons.codec.binary.Base64;
import py4j.ClientServer;
import py4j.GatewayServer;

Expand All @@ -28,6 +29,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -84,7 +86,7 @@ protected String[] getPy4jCommand() {
"--port", port == null ? DEFAULT_PORT : String.valueOf(port),
"--pyport", pythonPort == null ? DEFAULT_PYTHON_PORT : String.valueOf(pythonPort),
"--kernel", kernelName,
"--context", this.context
"--context", Base64.encodeBase64String(this.context.getBytes(StandardCharsets.UTF_8))
};
}

Expand Down