It looks like you're new here. If you want to get involved, click one of these buttons!
from queue import QueuemessageQueue = Queue()def read_queue(): while True: bulk_ticks = messageQueue.get() # do something like NASA or SpaceX here with this data# this is the only thing you should write in on_ticks, anything more would be terrible codingdef on_ticks(ws , ticks): messageQueue.put(ticks)# before starting KiteTicker, run read_queue in a thread so that it starts and gets hooked to the queue# below as an example, you can use new python 3 library also for threadingimport _thread_thread.start_new_thread(read_queue, ())
1. Initialize internal queue Q in the beginning of the program
2. Inside on_ticks you pass the data to the internal queue immediately
3. No need to launch threads inside on_ticks
4. You create thread in the main program for doing tasks
5. Code inside this thread reads from Q the internal queue and processes the data
and there should be a separate thread that is running and consuming this queue of ticks to process
this way you have decoupled on_ticks from computational load
This is a very simple approach, you can use a proper message broker also instead of python queue
You can use celery, rq.