1

The following code takes only 2 seconds when 10 requests are requested at the same time (ab -n 10 -c 10 http://127.0.0.1:5000/). Shouldn't it be 10 seconds because of GIL?

from flask import Flask from time import sleep app = Flask(__name__) @app.route("/") def hello_world(): sleep(1) return "<p>Hello, World!</p>" if __name__ == "__main__": app.run() # ab -n 10 -c 10 http://127.0.0.1:5000/ # This is ApacheBench, Version 2.3 # Server Software: Werkzeug/2.0.1 # Server Hostname: 127.0.0.1 # Server Port: 5000 # Concurrency Level: 10 # Time taken for tests: 2.021 seconds # Complete requests: 10 

Is sleep() blocking? And the code doesn't use asyncio even if it yields the control when calling sleep()?

2
  • 1
    I don't know a lot about the GIL, but I would think that while one (or several) threads are sleeping, that is the perfect situation for other threads to get work done. Commented Nov 11, 2021 at 2:59
  • Is sleep() blocking? And the code doesn't use asyncio if it yield the control when calling sleep()? Commented Nov 11, 2021 at 3:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.