
languagePluginLoader.then(() => {
  pyodide.loadPackage(["micropip", "cloudpickle"]).then( () => {
    pyodide.runPythonAsync(`
                    import micropip
                    import js
                    wheel_path = js.window.location.protocol + "//" + js.window.location.host + "/web/ray_web-0.0.1-py3-none-any.whl"
                    micropip.install(wheel_path)`)
                    .then(() => { pyodide.runPython(`
                    from ray import ray
                    ray.connect()
                    from ray.web import exec_work
                    `)
                  })
  var wsprotocol = "ws:"
  if (window.location.protocol == "https:") {
    wsprotocol = "wss:"
  }
  var wspath = wsprotocol + "//" + window.location.host + "/api/ws"
  var c = new WebSocket(wspath)
  c.onmessage = function(msg) {
    var workText = workTerms[Math.floor(Math.random() * workTerms.length)];
    $("#output").append("<p>" + workText + "...</p>")
    pyodide.globals.torun = msg.data
    pyodide.runPythonAsync("exec_work(torun)").then((res) => {
      $("#output").append("<p>Did work! 👏</p>")
      c.send(res)
    })
  }
  c.onopen = function() {
    $("#status").text("Status: connected!")
    c.send(JSON.stringify({
      status: 2,
      error_msg: "WebsocketWorker"
    }))
  }
  c.onclose = function() {
    $("#status").text("Status: disconnected")
  }
})
})
