1

I am trying to develop a multithreaded web server, it has the following task:

  1. Collect data from various data sources (API calls), I was planning to do this using multiple threads.

  2. Store the collected data in a memory data structure

  3. Do some processing on the data structure using another thread

  4. This data structure would be queried by the multiple clients; maybe I could also make separate threads for each client request.

Now regarding language and platform, I was considering either python or JAVA. I did some research on Flask framework for python, but I do not know how it will accommodate the multithreaded nature of web server. Please suggest how I could achieve the above functionality in my project.

2
  • 1
    flask is the way forward for you. take a look at this flaskbook.com Commented Mar 27, 2014 at 7:08
  • This is a very broad question. It all depends on the way you are running the application. Commented Mar 27, 2014 at 10:08

1 Answer 1

1

Flask, with some of the available addons, is very suited for what you want to do. Keep in mind that flask is pure python, and therefore you can access any of the excellent available python libraries.

As far as I understand what you have in mind, you can:

1- define a url that, when visited, executes the data gathering from external sources by means of, e.g. python-requests (http://docs.python-requests.org/en/latest/)

2- do the same periodically by scheduling the function above

3- store the collected data in a (e.g.) Redis database (which is memory based) or one of the many available databases (all of the nosql dbs have python bindings that you can access from a flask application)

4- define urls for the visiting clients to access the latest versions of the data. You will just need to define the data extraction functions (from redis or whatever you decide to use) and design a nice template to show them.

Flask/Werkzeug will take care of the multithreading necessary to handle simultaneous requests from different clients.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the detailed answer, the basic aim of my project is to try multithreading in Pyhton. Since i am planning to learn python in detail, I selected this project to brush up my multithreading skills. Could you tell me a way to achieve this using python threading model. I am open to frameworks othere then flask.
the point is that all web frameworks do handle multiple requests as a basic feature. Therefore they hide the complexity of multithreading. If you want to experiment with multithreading, you should look for something else than a web app

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.