简体   繁体   English

使用python的Web服务器

[英]Web server using python

I am trying to develop a multithreaded web server, it has the following task: 我正在尝试开发多线程Web服务器,它具有以下任务:

  1. Collect data from various data sources (API calls), I was planning to do this using multiple threads. 从各种数据源(API调用)收集数据,我打算使用多个线程来进行此操作。

  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. 现在关于语言和平台,我正在考虑python或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. 我对python的Flask框架进行了一些研究,但是我不知道它如何适应Web服务器的多线程性质。 Please suggest how I could achieve the above functionality in my project. 请提出如何在我的项目中实现上述功能的建议。

Flask, with some of the available addons, is very suited for what you want to do. Flask带有一些可用的插件,非常适合您要执行的操作。 Keep in mind that flask is pure python, and therefore you can access any of the excellent available python libraries. 请记住,flask是纯python,因此您可以访问任何出色的可用python库。

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, eg python-requests ( http://docs.python-requests.org/en/latest/ ) 1-定义一个URL,该URL在被访问时将通过例如python-requests( http://docs.python-requests.org/en/latest/ )执行从外部源收集的数据

2- do the same periodically by scheduling the function above 2-通过安排上述功能定期进行相同的操作

3- store the collected data in a (eg) 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) 3-将收集的数据存储在(例如)Redis数据库(基于内存)或许多可用数据库之一中(所有nosql数据库都有python绑定,您可以从flask应用程序访问)

4- define urls for the visiting clients to access the latest versions of the data. 4-定义供访问客户访问最新版本数据的URL。 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. 您只需要定义数据提取功能(从Redis或您决定使用的任何内容)并设计一个不错的模板即可显示它们。

Flask/Werkzeug will take care of the multithreading necessary to handle simultaneous requests from different clients. Flask / Werkzeug将处理必要的多线程处理来自不同客户端的同时请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM