0
0
Flaskframework~20 mins

WSGI servers (Gunicorn, uWSGI) in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WSGI Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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?
AGunicorn runs 4 instances of the Flask app in the same process, but only one handles requests at a time.
BGunicorn runs a single process with 4 threads, sharing the same memory space.
CGunicorn runs 4 separate worker processes, each handling requests independently, improving concurrency.
DGunicorn runs 4 worker processes but only one can handle requests at any moment.
Attempts:
2 left
💡 Hint
Think about how Gunicorn uses workers to handle multiple requests simultaneously.
📝 Syntax
intermediate
1: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?
Agunicorn -p 8080 app:app
Bgunicorn -b localhost:8080 app:app
Cgunicorn --bind 127.0.0.1:8080 app:app
Dgunicorn --bind 0.0.0.0:8080 app:app
Attempts:
2 left
💡 Hint
Binding to 0.0.0.0 means listening on all network interfaces.
🔧 Debug
advanced
2:30remaining
Why does uWSGI fail to start with this config snippet?
Given this uWSGI config snippet:
[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
AThe socket option requires 'http-socket' instead of 'socket' for HTTP serving.
BThe 'module' option should be 'app.app' not 'app:app'.
CThe 'master' option must be false to run multiple processes.
DThe 'processes' option must be set to 1 for uWSGI to start.
Attempts:
2 left
💡 Hint
Check if the socket type matches the expected protocol for HTTP serving.
state_output
advanced
2:30remaining
What is the output when using Gunicorn with multiple workers and a global counter?
Consider this Flask app:
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)
AThe responses could be any combination of 1, 2, or 3 repeated because each worker has its own counter.
BThe responses will be 1, 2, 3 in order because the counter is shared across workers.
CAll responses will be 3 because Gunicorn synchronizes the counter across workers.
DThe app will crash because global variables cannot be used with Gunicorn.
Attempts:
2 left
💡 Hint
Think about how global variables behave in multiple processes.
🧠 Conceptual
expert
3: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?
AEmperor mode allows uWSGI to run without configuration files, simplifying setup.
BEmperor mode automatically manages multiple uWSGI instances, restarting them if they crash, improving reliability.
CEmperor mode enables uWSGI to serve static files faster than Nginx.
DEmperor mode disables worker processes to reduce memory usage.
Attempts:
2 left
💡 Hint
Think about how production servers handle multiple apps and failures.