# Julia to other language communication

**URL:** <https://discourse.julialang.org/t/julia-to-other-language-communication/19361>\
**Category:** New to Julia\
**Created:** [January 7, 2019, 7:10pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361 "2019-01-07T19:10:12Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seanny123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/seanny123/32/5271_2.png) [@Seanny123](https://discourse.julialang.org/u/Seanny123)\
**Post date:** [January 7, 2019, 7:10pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/1 "2019-01-07T19:10:12Z")

</div>

If I want to communicate between processes written in different languages on Linux, I typically use pipes. I couldn’t find any documentation on this. However, I did find [examples of ZeroMQ](https://github.com/JuliaInterop/ZMQ.jl/blob/1d6de3fc6b448b38f020b571fa5b86121c6c2b81/docs/src/man/guide.md).

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [January 7, 2019, 7:24pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/2 "2019-01-07T19:24:17Z")

</div>

Do you have a specific language or use case in mind?

---

<div class="post-metadata">

**Author:** ![Seanny123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/seanny123/32/5271_2.png) [@Seanny123](https://discourse.julialang.org/u/Seanny123)\
**Post date:** [January 7, 2019, 7:58pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/3 "2019-01-07T19:58:50Z")

</div>

I would like to communicate between Julia and Python. I have a data-science application which uses Julia, but I’d like to create a basic REST server with Flask. Although I am investigating [writing the REST server with Julia](https://discourse.julialang.org/t/write-a-rest-interface-like-flask/18538), I’m passing off deployment to another team familiar with Python. Consequently, it would be ideal if Julia was abstracted away as much as possible. Previously, I tried using PyJulia, however I ran into [threading issues](https://github.com/JuliaPy/pyjulia#no-threading-support).

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [January 7, 2019, 8:48pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/4 "2019-01-07T20:48:20Z")

</div>

You can use pipes perfectly fine with Julia (at least, if just using stdin and stdout). What kind of data are you sending/receiving? Arrays? Strings? Arbitrary nested structures? Etc.

---

<div class="post-metadata">

**Author:** ![Seanny123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/seanny123/32/5271_2.png) [@Seanny123](https://discourse.julialang.org/u/Seanny123)\
**Post date:** [January 7, 2019, 8:51pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/5 "2019-01-07T20:51:52Z")

</div>

Strings of arbitrary length, but probably not larger than 256 characters.

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [January 7, 2019, 9:26pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/6 "2019-01-07T21:26:41Z")

</div>

> [@Seanny123](#):
>
> Previously, I tried using PyJulia, however I ran into [threading issues](https://github.com/JuliaPy/pyjulia#no-threading-support)

FYI, one way to workaround this is to make a “in-process service” by using PyJulia in a dedicated thread connected with other threads using (say) `queue.Queue` or `collections.deque`.

---

<div class="post-metadata">

**Author:** ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Post date:** [January 7, 2019, 9:30pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/7 "2019-01-07T21:30:57Z")

</div>

I’d check these options in the following order:

1. Try to resolve threading issues. Usually when deploying Flask application we use multiple worker processes, so I’m surprised threading appeared to be a problem.
2. REST API in Julia, possibly wrapped into a richer API in Flask. HTTP is really a common ground - rich format, easy to implement, easy to use from any client.
3. Pipes. Much fewer tools for data transfer than in HTTP, but if you are used to it, it might be a good starting point.
4. ZeroMQ or any other protocol.

---

<div class="post-metadata">

**Author:** ![Seanny123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/seanny123/32/5271_2.png) [@Seanny123](https://discourse.julialang.org/u/Seanny123)\
**Post date:** [January 7, 2019, 9:43pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/8 "2019-01-07T21:43:20Z")

</div>

Ah, I misunderstood the Python GIL constraint and will keep this in mind.

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [January 7, 2019, 9:52pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/9 "2019-01-07T21:52:21Z")

</div>

It’s actually `libjulia`’s problem. Currently it’s not thread-safe: [https://github.com/JuliaLang/julia/issues/17573](https://github.com/JuliaLang/julia/issues/17573)

But GIL could play a role if you consider the throughput of the REST service. It means that the service would be blocked whenever Julia does some calculation.

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [January 7, 2019, 9:58pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/10 "2019-01-07T21:58:05Z")

</div>

Here is one similar question with different option: [Which is the right way to integrate Julia program with Node.js](https://discourse.julialang.org/t/which-is-the-right-way-to-integrate-julia-program-with-node-js/19223)

---

<div class="post-metadata">

**Author:** ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)\
**Post date:** [January 7, 2019, 10:36pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/11 "2019-01-07T22:36:18Z")

</div>

I’m partial to [tcp sockets](https://docs.julialang.org/en/v1/manual/networking-and-streams/index.html#A-simple-TCP-example-1) myself. They are also [dead-simple with Python](https://docs.python.org/3/library/socketserver.html#examples), but if you want to go even bare-bones-er you could make a pair of fifos, since you like working with pipes. As far as I know, Julia doesn’t come with a function for this (or a function for hardlinks, weirdly), but it’s easy to write one:

```julia
function mkfifo(pathname, mode=0o666)
    err = ccall(:mkfifo, Cint, (Cstring, Cuint), pathname, mode)
    systemerror("couldn't make fifo, $(repr(pathname))", err != 0)
    pathname
end

```

Alternatively, you could just use Python’s `os.mkfifo`. works (more or less) the same as the above.

When you make the fifo, you can just open it and read and write to it like a normal file, but it blocks until it’s been opened both for reading and writing simultaneously. I only ever use them for one-way stuff, and TCP sockets for two-way.

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [January 7, 2019, 11:01pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/12 "2019-01-07T23:01:49Z")

</div>

As far as I know IJulia also uses ZeroMQ for communicating with Jupyter.

---

<div class="post-metadata">

**Author:** ![Seanny123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/seanny123/32/5271_2.png) [@Seanny123](https://discourse.julialang.org/u/Seanny123)\
**Post date:** [January 9, 2019, 3:29pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/13 "2019-01-09T15:29:40Z")

</div>

Does making `libjulia` thread-safe fall under the [“mutlithreading” compiler development priority](https://discourse.julialang.org/t/compiler-work-priorities/17623)?

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [January 9, 2019, 7:34pm UTC](https://discourse.julialang.org/t/julia-to-other-language-communication/19361/14 "2019-01-09T19:34:16Z")

</div>

This is very low-level part of Julia core for me so honestly, I don’t know. Having said that, my guess is that the parallel task runtime thing is unrelated. I thought “thread safety” in the list refers to thread safety of Julia code (i.e., usage of the core API), not about libjulia.
