Categories
Django Python

Python/Django: Running multiple commands in subprocesses

Here’s the scneario:

I have 4-5 different commands which I need to run every time I want to test my app. So I decided to write one command to rule them all. I run this one command and it runs the others using the subprocess module. It stores the processes created in a list. Then it goes to sleep inside a while loop waiting for a KeyboardInterrupt exception (which is fired when you press Ctrl + C – that is you send an interrupt signal from your keyboard). When this exception occurs, we iterate through the process ids we stored and kill them all. Simple, No?

Talk is cheap, here’s the code:

So this is how it looks on my machine:

Screen Shot 2015-09-29 at 5.16.44 PM

🙂

4 replies on “Python/Django: Running multiple commands in subprocesses”

Thank you for the post. I’m wondering where you put this code in your Django project…

Nice post ,i want to know if we dont add “runserver” command  , can we stop it with out kill signal

Comments are closed.