Vatsal Chavda
Vatsal Chavda

Reputation: 149

Execute other python script when django server is started

I have a Django project and other python script which is a ZMQ socket which continuously listens for message to perform some operation, ZMQ server script is an independent script which for now runs as python zmq_server.py in a terminal or cmd.

What I am trying to do is start the ZMQ server script when python manage.py runserver is called to start the django server.

I did some digging but found nothing related to this, is it possible to do something like this?

Upvotes: 2

Views: 391

Answers (1)

Rob Kwasowski
Rob Kwasowski

Reputation: 2780

You can run any script when your Django server starts by importing it in your settings.py at the top like this:

import zmq_server

Normally that's what you'd do for a script you're going to use in your project, but if you just want it to get executed you can do it like that as well.

Upvotes: 2

Related Questions