0
0
Flaskframework~20 mins

Gunicorn for production serving in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gunicorn Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you run Gunicorn with multiple workers?

You start a Flask app using Gunicorn with the command gunicorn -w 4 app:app. What is the main effect of specifying -w 4?

AGunicorn runs 4 worker processes to handle requests concurrently.
BGunicorn runs 1 worker process but limits requests to 4 per second.
CGunicorn runs 4 threads inside a single process to handle requests.
DGunicorn runs 4 instances of the Flask app in the same process.
Attempts:
2 left
💡 Hint

Think about how Gunicorn manages multiple requests in production.

📝 Syntax
intermediate
2:00remaining
Identify the correct Gunicorn command to serve a Flask app on port 8080

You want to serve your Flask app using Gunicorn on port 8080. Which command is correct?

Agunicorn -p 8080 app:app
Bgunicorn --port 8080 app:app
Cgunicorn --host 0.0.0.0 --port 8080 app:app
Dgunicorn --bind 0.0.0.0:8080 app:app
Attempts:
2 left
💡 Hint

Check Gunicorn's option for binding to an address and port.

🔧 Debug
advanced
2:00remaining
Why does Gunicorn fail to start with this command?

You run gunicorn app.py to start your Flask app but Gunicorn fails with an error. What is the likely cause?

AGunicorn cannot run Flask apps without a <code>run()</code> call.
BGunicorn requires the <code>--bind</code> option to specify a port.
CGunicorn expects the app as <code>module:app</code>, not a filename.
DGunicorn needs the app to be named <code>application</code> instead of <code>app</code>.
Attempts:
2 left
💡 Hint

Consider how Gunicorn imports the Flask app.

state_output
advanced
2:00remaining
What is the effect of setting the --timeout option in Gunicorn?

You run Gunicorn with --timeout 30. What happens if a worker takes longer than 30 seconds to respond?

AGunicorn queues the request until the worker finishes.
BGunicorn kills the worker and restarts it to free resources.
CGunicorn ignores the timeout and waits indefinitely.
DGunicorn logs a warning but keeps the worker running.
Attempts:
2 left
💡 Hint

Think about how Gunicorn handles stuck or slow workers.

🧠 Conceptual
expert
3:00remaining
Why is Gunicorn preferred over Flask's built-in server in production?

Choose the best reason why Gunicorn is used to serve Flask apps in production instead of Flask's built-in server.

AGunicorn handles multiple requests concurrently with worker processes, improving performance and reliability.
BFlask's built-in server does not support Python 3.12 and newer versions.
CGunicorn automatically converts Flask apps to asynchronous code for faster execution.
DFlask's built-in server requires a database connection, while Gunicorn does not.
Attempts:
2 left
💡 Hint

Consider concurrency and stability in production environments.