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

Can't spawn kernel from IHaskell notebook #3

Open
MMesch opened this issue May 21, 2018 · 0 comments
Open

Can't spawn kernel from IHaskell notebook #3

MMesch opened this issue May 21, 2018 · 0 comments

Comments

@MMesch
Copy link

MMesch commented May 21, 2018

This example works very well on my machine:
https://github.com/gibiansky/jupyter-haskell/blob/master/examples/client-kernel-info/Main.hs

When I paste the same code into the IHaskell notebook (slightly adapted as shown below), the IHaskell notebook blocks after the spawnProcess call. Is there any way that allows to spawn a python kernel from the IHaskell notebook?

Cell1:

import           Control.Monad.IO.Class (MonadIO(liftIO))
import           System.Process (spawnProcess)

import           Data.Text (pack)
import           Jupyter.Client (runClient, sendClientRequest, ClientHandlers(..), connectKernel,
                                 defaultClientCommHandler, findKernel, writeProfile, Kernelspec(..))
import           Jupyter.Messages (ClientRequest(KernelInfoRequest), KernelReply(KernelInfoReply),
                                   KernelRequest(InputRequest), ClientReply(InputReply))

handlers :: ClientHandlers
handlers = ClientHandlers {
    commHandler = defaultClientCommHandler,
    kernelRequestHandler = \_ req ->
        case req of
        InputRequest{} -> return $ InputReply (pack "Fake Stdin"),
    kernelOutputHandler = \_ _ -> return ()
    }

Cell2

-- Find the kernelspec for the python 3 kernel
Just kernelspec <- findKernel (pack "python3")

-- Start the client connection
runClient Nothing Nothing handlers $ \profile -> do
    -- Write the profile connection file to a JSON file
    liftIO $ writeProfile profile "profile.json"

-- Launch the kernel process, giving it the path to the JSON file
let command = kernelspecCommand kernelspec "" "profile.json"
_ <- liftIO $ spawnProcess (head command) (tail command)

-- Send a kernel info request and get the reply
connection <- connectKernel
KernelInfoReply info <- sendClientRequest connection KernelInfoRequest
liftIO $ print info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant