How to Run Multiple Processes Simultaneously.

syscrews
2 min readOct 3, 2023

--

How to Run Multiple Processes Simultaneously.

As a Django developer, I have to run multiple processes while developing, such as the Django server, a JavaScript compiler, and Celery. Launching these processes separately can be time-consuming and tedious. Just try opening three terminal windows, and you’ll understand what I mean.

Finally, I found a solution in the Rails community. In Rails, when they do development, they launch a single bin/dev bash file, which takes care of the rest: it launches the dev server, the asset pipeline, and so on. And eureka, we can do the same in Django! So, I adopted their approach for Django and want to share it with you.

Step 1 — Create a bin/dev file

To get started, create a bin/dev bash file in your project’s root directory. In this file, we use a bash script to run multiple processes at once.

#!/usr/bin/env bash
if ! command -v honcho &> /dev/null
then
echo "Installing honcho…"
pip install honcho
fi
honcho start -f Procfile.dev

In this file, we install and run a Python package called Hocho, a tool for managing Procfile-based applications.

Once you have created the bin/dev file, set its permissions by running:

chmod +x ./bin/dev

Step 2 — Create a Procfile

For Honcho, we need a Procfile, a file in which you can declare multiple processes, or terminal commands, to launch at the same time and run simultaneously. This is exactly what we need: to run the server, Webpack, Celery, all at once.

Let\’s create a Procfile.dev file in the root directory of your project. In this file, specify the commands for each process that you want to run:

django: python manage.py runserver
js: webpack -w
css: python manage.py tailwind start
celery: celery

In this example, the Procfile.dev launches the Django dev server, Webpack, Tailwind CSS compiler, and Celery worker all at once.

Step 3 — Ready? Launch!

To launch all the processes, run the following command in your terminal:

./bin/dev

And that’s it! Watch the screen and enjoy the flow of command logs. You’re Thomas Anderson!

Give it a try and see how it can improve your workflow.

Hey, if you’ve found this useful, please share the post to help other folks find it:

--

--

No responses yet