django run websocket client in background

So when I run the WebSocket client I can no longer reach the Django app like I can’t connect to, here is the WebSocket file:

import websocket, json, pprint
from datetime import datetime

socket = "wss://"

def on_message(ws, msg):
    message = json.loads(msg)
    messageData = message['k']

    if messageData['x']:
        # get_data(messageData)
        timestamp = float(messageData['t'])
        symbol = messageData['s']
        interval = messageData['i']
        closeprice = float(messageData['c'])
        openprice = float(messageData['o'])
        highprice = float(messageData['h'])
        lowprice = float(messageData['l'])
        datetime_ob = datetime.fromtimestamp(timestamp / 1000)

        data = {'timestamp': timestamp, 'symbol': symbol, 'interval': interval, 'closeprice': closeprice,
                'openprice': openprice, 'highprice': highprice, 'lowprice': lowprice, 'datetime_ob': datetime_ob}


def on_open(ws):

def on_error(wsapp, err):
    print("Got a an error: ", err)

def runwss():
    stream = websocket.WebSocketApp(socket, on_error=on_error, on_open=on_open, on_message=on_message)


And I inited it in apps file:

from django.apps import AppConfig

class ServiceGetDataConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'service_get_data'

    def ready(self):
        import service_get_data.wss

And as I said I can’t reach anymore so what shall I do in this case?


I searched online and ended up with using Threading module:

thread = threading.Thread(target=runwss)