views:

61

answers:

1

I'm trying to understand threading better. If I create a program that allows people to upload a photo and then I create a new process to resize the image in a hundred ways (taking 5 seconds or longer), and the main program returns a response HTML page to the user saying "Thanks. You're done!", can the other process still be working at this point? Assume that I'm using the multiprocessing module vs GIL threading with subprocess.

+7  A: 

Considering a Message or Job Queue is a good idea when you have background processing to do. This way you won't have to write your own code to handle job scheduling, priority etc. You can also add more servers to the queue when the first one starts running out of capacity.There's a package called Celery that is supposed to provide MQ access to django apps.

In your case, you might create an animated 'throbber' on your page that periodically polls the server though ajax. When the image processing is done, you can update the page.

Dana the Sane
I'm not too worried about the user seeing the results to be honest. I'm just worried about a page loading for 10 seconds. I'd rather the page only take 2 seconds (file upload and basic HTML rendering + latency) and then the tricky sheesh happening later.
orokusaki
+1 for Celery..
Daniel Roseman