send_header ( "Content-type", "text/html" ) self. status in : happy_clusters += 1 # Return 200 response if there is at least 1 cluster running, # and make sure all running clusters are happy if total_clusters and happy_clusters = total_clusters : response_code = 200 else : response_code = 500 self. setup () from django_q.monitor import Stat from django_q.conf import Conf # Set host and port settings hostName = "localhost" serverPort = 8080 class HealthCheckServer ( BaseHTTPRequestHandler ): def do_GET ( self ): # Count the clusters and their status happy_clusters = 0 total_clusters = 0 for stat in Stat. setdefault ( "DJANGO_SETTINGS_MODULE", "my.settings.path" ) # All django stuff has to come after the setup: django. array (, ]) # async_task them with a group label to the cache backend for w in widths : async_task ( parzen_estimation, sample, x, w, group = 'parzen', cached = True ) # return after 100 results return result_group ( 'parzen', count = 100, cached = True )ĭjango Q is not optimized for distributed computing, but this example will give you an idea of what you can do with task Groups.Īlternatively the parzen_async() function can also be written with async_iter(), which automatically utilizes the cache backend and groups to return a single result from an iterable:įrom rver import BaseHTTPRequestHandler, HTTPServer from mtt_ import EMAIL_USE_TLS import os import django # Set the correct path to you settings module os. Multivariate_normal ( mu_vec, cov_mat, 10000 ) widths = numpy. shape ) # create 100 calculations and return the collated result def parzen_async (): # clear the previous results delete_group ( 'parzen', cached = True ) mu_vec = numpy. abs ( row ) > ( 1 / 2 ): break else : k_n += 1 return h, ( k_n / len ( x_samples )) / ( h ** point_x. # Group example with Parzen-window estimation import numpy from django_q.tasks import async_task, result_group, delete_group # the estimation function def parzen_estimation ( x_samples, point_x, h ): k_n = 0 for row in x_samples : x_i = ( point_x - row ) / h for row in x_i : if numpy.