How to run a HTTP.jl server in parallel, while doing computations in the foreground?

A quick update on this. I had another go at my original probilem, and found a workaround. By explicitly allocating threads to the interactive as well as the default pool, and spawning the CPU consuming work on a default thread, I could get it to work as epxected:

$ julia --threads=1,1
julia> using HTTP
julia> HTTP.serve!(Returns(HTTP.Response("ok")))
[ Info: Listening on: 127.0.0.1:8081, thread id: 2
# curl http://localhost:80801 -> ok
julia> fib(n) = return n <= 2 ? 1 : fib(n - 1) + fib(n - 2)
julia> fetch(Threads.@spawn fib(47))
# curl http://localhost:80801 -> still responds, even while computing

Note the first and last lines of the above code block.

1 Like