1

I have an upload page in django powered site. The end-users upload the documents from that page. The back end processing of that uploaded document can take several minutes. How do i handle multiple end-users' request in the back end? I have thought of using thread for each end-user's request. However, i am finding it difficult in coding that how do i create a new thread as soon as some user uploads a document. A sample example or demo would be highly appreciated. Thanking you in advance!!!

2 Answers 2

2

The other way to start a thread is to give your callable to the Thread constructor, like this:

from threading import Thread

processing_thread = Thread(target=your_heavy_lifting_function_name)
processing_thread.start()
Sign up to request clarification or add additional context in comments.

Comments

1

Without more information its hard to say what exactly, but threads sound like a reasonable idea. To create a thread in python, you do the following:

from threading import Thread
class Worker(Thread):
    def __init__(self):
        Thread.__init__(self) #Runs the thread's constructor

    #Method that is run when the new thread starts
    def run(self):
        #Whatever data processing you have to do can go here
        while True:
            print "Hello from Worker"

w = Worker()
w.start() #Starts a new thread which executes the object's run function

2 Comments

Thanks for your advice. Do i have to use a callback handler so that if any user uploads a document, this handler automatically spawns a new thread for that user's request?
If you're uploading the files asynchronously (e.g. using Ajax) and you could use a callback to do something client-side in Javascript when the processing of the file is finished (such as redirecting the user to a new page).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.