# Addprocs: specify both multithreading and active environment

**URL:** <https://discourse.julialang.org/t/addprocs-specify-both-multithreading-and-active-environment/80427>\
**Category:** Julia at Scale\
**Tags:** distributed\
**Created:** [May 3, 2022, 2:00pm UTC](https://discourse.julialang.org/t/addprocs-specify-both-multithreading-and-active-environment/80427 "2022-05-03T14:00:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [May 3, 2022, 2:00pm UTC](https://discourse.julialang.org/t/addprocs-specify-both-multithreading-and-active-environment/80427/1 "2022-05-03T14:00:15Z")

</div>

Let’s say I want to add a process with 8 threads. This is easy:

```julia
using Distributed
addprocs(1, exeflags="-t 8")

```

One can check that `@fetchfrom 2 Threads.nthreads()` returns 8 as expected.

But, if I try to specify the environment as well, only one thread appears.

```julia
using Distributed
addprocs(1, exeflags="--project=$(Base.active_project()) -t 8")
@fetchfrom 2 Threads.nthreads()

```

Is it a bug, or am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [May 3, 2022, 2:46pm UTC](https://discourse.julialang.org/t/addprocs-specify-both-multithreading-and-active-environment/80427/2 "2022-05-03T14:46:18Z")

</div>

I found out this can work:

```julia
julia> addprocs(1, exeflags=["--threads=4", "--project=$(Base.active_project())"])

```

It’s maybe not strictly a bug, or then a doc bug, I would still file an issue.

What I wrote before figuring out the above (and you may want this to work, or the docs explicit this will not work):

The s in exeflags implies to me more than one allowed, and I tried switching around:

```julia
julia> addprocs(1, exeflags="--threads=4 --project=$(Base.active_project())")
ERROR: julia: -t,--threads=<n> must be an integer >= 1
ERROR: TaskFailedException

    nested task error: Unable to read host:port string from worker. Launch command exited with error?
[stacktrace skipped]

```

It seems nonsensical, as in the parser trying to split up -t and the --project part not working. I guess in your case -t was just ignored. Is there a different way to invoke this?

---

<div class="post-metadata">

**Author:** ![lmtzx9h4qqnt](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lmtzx9h4qqnt](https://discourse.julialang.org/u/lmtzx9h4qqnt)\
**Post date:** [April 16, 2024, 5:11pm UTC](https://discourse.julialang.org/t/addprocs-specify-both-multithreading-and-active-environment/80427/3 "2024-04-16T17:11:02Z")

</div>

I think the problem is that `exeflags` is supposed to be a `Cmd` (this was documented incorrectly for a while, and either way isn’t explained in the docstrings). The code does happen to work for a `String` if this `String` only contains a single option, otherwise it’s problematic.

In other words, the following works:

```julia
using Distributed
addprocs(1, exeflags=`--project=$(Base.active_project()) -t 8`)
@fetchfrom 2 Threads.nthreads()

```
