Work - Running multiple process in one sessionΒΆ
Usage: work [ADDRESS] [-h] [--completion COMPLETION]
Run your whole django projects in one command.
Arguments
[ADDRESS] Django server address (Default: 127.0.0.1:8000)
Help
[-h, --help] Show this message and exit.
[--completion COMPLETION] Use --completion generate to print shell-specific completion source. Valid options: generate, complete.
This command allows you to run multiple commands simultaneously. Typically, when working with a large or growing django project, you
reach a point where you need to run multiple processes to run your project. This might include a Redis server, a Tailwind compile command,
a task queue worker, etc. With this command, you can run all these commands in parallel within a single terminal.
It execute the commands by reading your pyproject.toml
file and running the commands defined in the [tool.falco.work]
section.
Here is an example of what a falco work configuration might looks like:
[tool.falco.work]
server = "python manage.py migrate && python manage.py tailwind runserver"
redis = "redis-server"
worker = "python manage.py qcluster"
Examples
falco work
You can customize the address of the Django server just like you would when running runserver
directly
falco work 127.0.0.1:8001
falco work 8002
Under the hood, this command utilizes honcho to execute the defined commands, with each command running in its own separate process.
Note
If no command is defined in the pyproject.toml
file, the default behavior is to run the Django runserver
command.
I was inspired by the forge-work package to create this command. It is a more powerful version of the one I have here. The forgepackages repository has some great tools for Django development in general. I would recommend checking them out as they might have something of interest to you.
This command runs in the foreground, so as soon as you kill the current terminal, all processes will be stopped. It is meant for development purposes only. If you launch it and the Django server fails, indicating that the port is already in use, there is a chance that a previously running server was not properly killed and is still running. To kill all previous running processes, run the following command:
$ lsof -i :8000 -sTCP:LISTEN -t | xargs -t kill # replace 8000 with the port you are using
This command was copied from this blog post.