[Xiao Mu learns Python] Python realizes Web server (Flask, gevent)

Article directory 1 Introduction 1.1 Function list 1.2 Supported platforms 1.3 Installation 2. Example of getting started with gevent 2.1 File I/O 2.2 MySQL 2.3 redis 2.4 time 2.5 requests 2.6 sockets 2.7 Concurrent fetching text 2.8 Concurrent grabbing pictures 2.9 Producer-Consumer 3. Other examples of gevent 3.1 StreamServer 3.2 WSGI server 3.3 flask 3.4 […]

gevent coroutine, improve IO efficiency

Simple improvements using coroutines Using gevent is very simple. You only need to put the task into the list of coroutines to be opened. The task will be switched according to the IO operation, and the speed will be significantly faster. It should be noted that monkey.patch_all() needs to be compiled before the request. Otherwise, […]

The most comprehensive explanation of SpringEvent

Directory 1. When must springEvent be used? 2. Application scenarios of SpringEvent in actual projects 3. Why not call other business interfaces directly in the code but use SpringEvent 4. Sample code combined with project scenarios Five, maybe you want to ask (also my doubts) 1. When to use springEvent Spring Event is an event […]

Python Flask uses gevent or grpc.gevent module to implement asynchronous non-blocking

Directory 0. Preface: 1. Introduction to gevent.monkey: 2. Introduction to grpc.gevent: 3. Flask Demo code 4. Pressure test results 5. Stress test report 6 Conclusion 0. Foreword: Flask itself is not an asynchronous framework, so there will be performance bottlenecks when processing high concurrent requests. However, Flask can improve concurrency performance through integration with other […]

Python’s various network request libraries urllib3 requests aiohttp request http and https efficiency comparison, multi-threading, gevent, asyncio comparison, super large thread pool, 2n + 1 thread pool comparison…

The three purposes of this article are not to go astray by just obsessing with concepts. Some people think that there is a set of concepts, but in fact it is not what they think. This article uses various network request libraries, various concurrency modes, and thread pools of various sizes to test 50,000 requests […]

Flask+Gunicorn(gevent)+sqlalchemy high concurrency solution research

1. Using Flask as the server framework can run in the form of python code.py, but this method cannot be used in the production environment and is unstable. For example: there is a certain probability that the connection will time out without returning. 1. By setting the parameters of app.run(), the multi-process effect can be […]

[Solved] gunicorn turns on gevent mode, and a timeout error is reported when the service is started, and the service cannot be started.

Error [[2022-08-25 08:26:45+0000]] CRITICAL [glogging.py:255] WORKER TIMEOUT (pid:669)’ Solution Reference: It may be the coroutine model. The default value of worker_connections is too large, which makes it impossible to get up. If it is changed to multi-threading and gthread model, the service can be up. https://github.com/benoitc/gunicorn/issues/2608 https://github.com/benoitc/gunicorn/issues/1840 It has been said many time to not […]

[Solved] Flask: Use SocketIO to implement WebSocket and front-end Vue for real-time push (gevent-websocket, flask-socketio, flask does not have the problem of running on 127..)

Foreword This article aims to record the problem that the WebSocket always fails to connect to the front-end Vue in the process of using the Flask framework and the front-end cannot get data. And after using the library package gevent-websocket with WebSocket related functions, after running the Flask project, the console does not display the […]

[Solved] The flask service started by gevent reports the error Too many open files

The flask service started by gevent reports the error Too many open files Traceback (most recent call last): File “/data/miniconda3/envs/ner_py37/lib/python3.7/site-packages/gevent/baseserver.py”, line 227, in _do_read File “/data/miniconda3/envs/ner_py37/lib/python3.7/site-packages/gevent/server.py”, line 198, in do_read OSError: [Errno 24] Too many open files 2022-07-13T12:23:52Z <WSGIServer at 0x7fc47ec6d790 fileno=4 address=0.0.0.0:8088> failed with OSError This problem generally occurs when the interface is called […]