Challenge - 5 Problems
WSGI Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when you run a Flask app with Gunicorn using multiple workers?
Consider a Flask app started with Gunicorn using the command
gunicorn -w 4 app:app. What is the effect of specifying -w 4?Attempts:
2 left
💡 Hint
Think about how Gunicorn uses workers to handle multiple requests simultaneously.
✗ Incorrect
Gunicorn creates multiple worker processes (4 in this case). Each worker runs independently and can handle requests concurrently, improving performance under load.
📝 Syntax
intermediate1:30remaining
Which Gunicorn command correctly binds the server to port 8080?
You want to start a Flask app with Gunicorn and bind it to port 8080 on all interfaces. Which command is correct?
Attempts:
2 left
💡 Hint
Binding to 0.0.0.0 means listening on all network interfaces.
✗ Incorrect
The --bind option specifies the IP and port. 0.0.0.0:8080 means listen on all interfaces at port 8080.
🔧 Debug
advanced2:30remaining
Why does uWSGI fail to start with this config snippet?
Given this uWSGI config snippet:
What is the likely cause of failure?
[uwsgi] module = app:app master = true processes = 4 socket = 127.0.0.1:5000
What is the likely cause of failure?
Flask
[uwsgi] module = app:app master = true processes = 4 socket = 127.0.0.1:5000
Attempts:
2 left
💡 Hint
Check if the socket type matches the expected protocol for HTTP serving.
✗ Incorrect
Using socket creates a raw socket expecting a WSGI server behind a proxy. To serve HTTP directly, http-socket is needed.
❓ state_output
advanced2:30remaining
What is the output when using Gunicorn with multiple workers and a global counter?
Consider this Flask app:
If you run it with
from flask import Flask
app = Flask(__name__)
counter = 0
@app.route('/')
def index():
global counter
counter += 1
return str(counter)If you run it with
gunicorn -w 3 app:app and make 3 requests, what is the possible output sequence?Flask
from flask import Flask app = Flask(__name__) counter = 0 @app.route('/') def index(): global counter counter += 1 return str(counter)
Attempts:
2 left
💡 Hint
Think about how global variables behave in multiple processes.
✗ Incorrect
Each Gunicorn worker is a separate process with its own memory. The global counter is not shared, so each worker increments its own counter independently.
🧠 Conceptual
expert3:00remaining
Why is using uWSGI with Emperor mode beneficial in production?
What is the main advantage of running uWSGI in Emperor mode for managing multiple Flask apps?
Attempts:
2 left
💡 Hint
Think about how production servers handle multiple apps and failures.
✗ Incorrect
Emperor mode supervises multiple uWSGI instances, automatically restarting them if they fail, which helps keep apps running smoothly in production.