Do you mean that the results are returned to the database or do you want to create django-views directly from your independently working code?
If you have large amounts of data, I like to use Pythons multiprocessing . You can create a generator that populates JoinableQueue various tasks and a pool of Workers consuming various Tasks. Therefore, you should be able to maximize the use of resources in your system.
The multiprocessing module also allows you to perform several tasks over the network (for example, multiprocessing.Manager() ). With that in mind, you should easily scale things if you need a second machine to process data on time.
Example:
This example shows how to create multiple processes. The generator function should query the database for all new entries requiring heavy lifting. Consumers take individual items from the queue and perform actual calculations.
import time from multiprocessing.queues import JoinableQueue from multiprocessing import Process QUEUE = JoinableQueue(-1) def generator(): """ Puts items in the queue. For example query database for all new, unprocessed entries that need some serious math done..""" while True: QUEUE.put("Item") time.sleep(0.1) def consumer(consumer_id): """ Consumes items from the queue... Do your calculations here... """ while True: item = QUEUE.get() print "Process %s has done: %s" % (consumer_id, item) QUEUE.task_done() p = Process(target=generator) p.start() for x in range(0, 2): w = Process(target=consumer, args=(x,)) w.start() p.join() w.join()
source share