Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run multiple commands in parallel - fastapi and npm for example #71

Open
FabienArcellier opened this issue Dec 31, 2023 · 0 comments
Open
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@FabienArcellier
Copy link
Owner

FabienArcellier commented Dec 31, 2023

The contextmanager alfred.parallel allow a developper to run multiple commands simulatneously and in a single terminal. It's useful to run fullstack apps, for example to run npm, fastapi and a database in same time.

When the user interrupts a command with CTRL+C, all commands that are currently executing are interrupted. If it is another signal as sigquit, it is forwarded to the commands being executed by alfred.

Log messages are prefixed with the command name in square brackets like in docker-compose to be able to track what is happening.

[front] 2022-12-01 12:56:54 hello world

usage

The developer declare the commands to be executed simultaneously in an alfred.parallel context block. Each of the commands will run independently of each other.

with alfred.parallel() as p:
  p.run(npm, ["run"], name="front")
  p.run(python, ["run"], name="back")

The commands are waited for indefinitely before exiting the alfred.parallel block. It is possible to disable this behavior and explicitly check the end of a command by setting the attribute wait to False. The instruction wait allow to wait the end of a command explicitely.

with alfred.parallel(wait=False) as p:
  p.run(npm, ["run"], name="front")
  p.run(python, ["run"], name="back")
  p.wait(commands=['front', 'back'])

alfred commands can be invoked in an alfred.parallel block.

with alfred.parallel() as p:
  p.invoke_command("frontend:run", name="front")
  p.invoke_command("backend:run", args={'verbose': verbose}, "back")
@FabienArcellier FabienArcellier added the enhancement New feature or request label Dec 31, 2023
@FabienArcellier FabienArcellier added this to the 2.3.0 milestone Dec 31, 2023
@FabienArcellier FabienArcellier self-assigned this Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant