Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in Clojure by

In https://github.com/cnuernber/dtype-next/issues/52 we are planning to make interoperability between java, clojure and other non-jvm-languages easier when using machine learning libraries that are written in clojure. We also want to create an efficient path for dataframes and ndarrays into julia (libjulia-clj) and python (libpython-clj).

I have made some significant progress with clojure integration from java here: https://github.com/invesdwin/invesdwin-context/blob/master/invesdwin-context-parent/invesdwin-context-clojure/src/main/java/de/invesdwin/context/clojure/pool/
(test cases to reproduce the issue are in the same project)

It seems single threaded tests run fine now, but when using more than 1 thread the bindings don't seem to work. From what I read clojure should use threadlocals for namespace variables. But maybe I am missing some system property to isolate everything properly? (similar to jruby's org.jruby.embed.localcontext.scope=threadsafe; https://github.com/jruby/jruby/wiki/RedBridge#Context_Instance_Type)

Am I doing something wrong or is clojure not capable to be called from multiple threads in parallel without namespace conflicts?
It seems clojure binds itself to the first thread that initialized it and any other thread runs into binding errors:

As a workaround I could keep interaction with clojure limited to a single thread and delegate script executions to that single thread via an executor. Though it would be more efficient if the thread local isolation of clojure worked with more than one thread.

1 Answer

0 votes
ago by
selected ago by
 
Best answer

I have found a workaround by using separate namespaces for each thread: https://github.com/cnuernber/dtype-next/issues/52#issuecomment-1013685393

So all testcases are green now.

...