clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.09k stars 68 forks source link

Question: on using a remote process for the Python interpreter #6

Closed teodorlu closed 5 years ago

teodorlu commented 5 years ago

Hello Chris!

I really enjoyed listening to Scicloj meeting #4. You're doing interesting work here. I feel that you're setting the Clojure community up for an interop story with Python that's similar to how we're able to make use of Java.

I have a question, if you don't mind. Per now, I can use my own interpreter of choice like this:

(require '[libpython-clj.python :as py]
         '[libpython-clj.jna.base])

(defn get-python [_]
  "/home/teodorlu/opt/anaconda3/bin/python")

(alter-var-root #'libpython-clj.jna.base/*python-library* #'get-python)

I would like to use libpython-clj to interface with a running Python process that's not started from within the Clojure process, but "on its own terms". A possible process could look like this:

  1. Make some changes to the remote Python interpreter allow libpython-clj to ... do what it needs to do.
  2. Start a Clojure process
  3. Point the Clojure process to the running Python process
  4. Evaluate Python code in that context.

The reason why I can't just start a new process, is that the Python process is started by another application, and I need access to the application state, as the user interacts with the state.

I spent some time reading the libpython-clj source code, but I must admit that this is above my level, hence I'm asking.

Thanks again for your work, and have a nice day! Teodor

cnuernber commented 5 years ago

@teodorlu Hey Teodor!

This isn't currently possible; it would take something like launching a clojure process that did the networking stuff and the eval'ed things in a python context.

Is there a python equivalent to nrepl? Maybe some bindings around that would do something like what you want.

teodorlu commented 5 years ago

Thanks for the clear reply -- I wasn't aware of how libpython-clj did its internal work, so the clarification was really helpful to me.

Something similar to NREPL seems like the way to go.

Closing this. Thanks again!

Teodor