JuliaLang / IJulia.jl

Julia kernel for Jupyter
MIT License
2.78k stars 409 forks source link

Extra thread when using IJulia #1072

Open carstenbauer opened 1 year ago

carstenbauer commented 1 year ago

In the REPL (with JULIA_NUM_THREADS=6)

Threads.nthreads(:default) # gives 6
count(i -> threadpool(i) == :default, 1:Threads.maxthreadid()) # gives 6

as expected. However, in Jupyter (IJulia) I get

Threads.nthreads(:default) # gives 6
count(i -> threadpool(i) == :default, 1:Threads.maxthreadid()) # gives 7 ?!?!

I assume that the extra thread is the heartbeat thread. But in any case, this seems inconsistent. Upstream issue?

stevengj commented 1 year ago

Yup.

I'm not sure if there is a way to prevent Julia from claiming ownership of this thread? See also https://github.com/JuliaLang/julia/issues/47196.

Or maybe Threads.nthreads should not count foreign threads.