pixi icon indicating copy to clipboard operation
pixi copied to clipboard

when using `&`, `pixi run ...` errors with `spawn_local` called from outside of a `task::LocalSet` or LocalRuntime

Open hab25 opened this issue 1 year ago • 4 comments

Checks

  • [x] I have checked that this issue has not already been reported.

  • [x] I have confirmed this bug exists on the latest version of pixi, using pixi --version.

Reproducible example

# pixi.toml
[workspace]
channels = ["conda-forge"]
name = "pixi-test"
platforms = ["linux-64"]

[tasks.failing]
cmd = [
    "echo",
    "bar",
    "&",
    "echo",
    "qux"
]

[tasks.not-failing]
cmd = [
    "echo",
    "bar",
    "&&",
    "echo",
    "qux"
]
$ ~/.pixi/bin/pixi run failing
✨ Pixi task (failing): echo bar & echo qux

thread 'main2' panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.44.2/src/task/local.rs:418:29:
`spawn_local` called from outside of a `task::LocalSet` or LocalRuntime
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

thread 'main' panicked at src/main.rs:49:10:
Tokio executor failed, was there a panic?: Any { .. }

Issue description

$ ~/.pixi/bin/pixi run not-failing
✨ Pixi task (not-failing): echo bar && echo qux
bar
qux
$ ~/.pixi/bin/pixi --version
pixi 0.47.0

Expected behavior

$ ~/.pixi/bin/pixi run failing
✨ Pixi task (failing): echo bar & echo qux
bar
qux

hab25 avatar May 15 '25 18:05 hab25

I think the problem here is that & in bash means run the command in background where && run them both.

I guess that we are spawning a separate thread for the first command that fail for some reason. ~~Maybe we need to pass the current runtime, so the thread will be started there.~~

I will need to check why it happens when we pass the command to deno_task_shell. Maybe we don't correctly convert the command to a deno script.

nichtmacho avatar May 22 '25 08:05 nichtmacho

maybe we need to wrap invocation of deno task shell with this: https://docs.rs/tokio/latest/tokio/task/struct.LocalSet.html#use-with-run_until

nichtmacho avatar May 22 '25 09:05 nichtmacho

I got the same error when I was trying to run a couple Pixi tasks in the background.

Reproducible example

Configuration pixi.toml

# pixi.toml

[workspace]
channels = ["conda-forge"]
name = "pixi_tests"
platforms = ["win-64"]
version = "0.1.0"

[tasks]
thread-1 = "(python -c 'intput()' &) ; echo '$!' > pid1.txt"
thread-2 = "(python -c 'from time import sleep; sleep(5); import this' > out2.txt &) ; echo '$!' > pid2.txt"

[tasks.execute-threads]
cmd = "wait $(cat pid2.txt) && kill $(cat pid1.txt) && wait $(cat pid1.txt) && echo 'Threads completed! Output: \n$(cat out2.txt)'"
depends-on = ["thread-1", "thread-2"]

[dependencies]
python = "3.13.*"

PowerShell 7 command (Win 11)

pixi run execute-threads

Output

PS $HOME\Data\pixi_tests> pixi run execute-threads
✨ Pixi task (thread-1): (python -c 'intput()' &) ; echo '$!' > pid1.txt

thread 'main2' panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\tokio-1.44.2\src\task\local.rs:418:29:
`spawn_local` called from outside of a `task::LocalSet` or LocalRuntime
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

thread 'main' panicked at src\main.rs:49:10:
Tokio executor failed, was there a panic?: Any { .. }

Issue description

PS $HOME\Data\pixi_tests> pixi --version
pixi 0.48.0

I double-checked my syntax and the commands I used. The error message I displayed above appears to be equivalent to the OP's message.

Expected behavior

With this specific example, I would expect the following actions to occur:

  1. When the execute-threads task is run, each dependency should be started as a background process, saving their PID's to text files for later use.
  2. Next, the second thread's PID will utilized by the shell to wait for its completion.
  3. Once finished, a SIGINT (Keyboard interrupt) signal will be sent to the first thread to trigger its completion.
  4. After both threads have been completed, the output of the second thread should be echoed ("The Zen of Python").

Let me know if you need anymore info!

bpythonistic avatar Jul 02 '25 18:07 bpythonistic

This has been fixed in recent versions of pixi. Works on 0.51.0.

baszalmstra avatar Aug 15 '25 12:08 baszalmstra