I'm making a simple Python function where i have a function running on the main thread, called Updater, which now only prints something but it will do other tasks, and it's called by schedule, and another function that i want to run in parallel, so for that i'm using threading.
Here is my attempt:
import websocket, json, time, schedule, logging, cfscrape, threading, requests
def Run():
def process_message(ws,msg):
print(msg)
def Connect():
websocket.enableTrace(False)
ws = websocket.WebSocketApp("wss://stream.binance.com/stream?streams=btcusdt@depth", on_message = process_message)
ws.run_forever()
def Updater():
print('Updating..')
threading.Thread(target=Run).start()
schedule.every(1).seconds.do(Updater)
while True:
schedule.run_pending()
time.sleep(1)
What i'm trying to do is to have this script executing the websocket connection and the scheduled function at the same time in parallel using threads. The problem with my code is that Run is not getting started. Only Updater will start executing.
Can anyone help me out on this? Am i using threads the wrong way? Thanks in advance.