MCPcopy
hub / github.com/benoitc/gunicorn / app

Function app

examples/dirty_example/wsgi_app.py:30–225  ·  view source on GitHub ↗

WSGI application that demonstrates dirty worker integration.

(environ, start_response)

Source from the content-addressed store, hash-verified

28
29
30def app(environ, start_response):
31 """WSGI application that demonstrates dirty worker integration."""
32 path = environ.get('PATH_INFO', '/')
33 method = environ.get('REQUEST_METHOD', 'GET')
34
35 # Parse query string
36 query = parse_qs(environ.get('QUERY_STRING', ''))
37
38 # Get dirty client
39 client = get_dirty_client()
40
41 try:
42 if path == '/':
43 result = {
44 "message": "Dirty Workers Demo",
45 "dirty_enabled": client is not None,
46 "pid": os.getpid(),
47 "endpoints": {
48 "/models": "List loaded models",
49 "/load?name=MODEL": "Load a model",
50 "/inference?model=NAME&data=INPUT": "Run inference",
51 "/unload?name=MODEL": "Unload a model",
52 "/fibonacci?n=NUMBER": "Compute fibonacci",
53 "/prime?n=NUMBER": "Check if prime",
54 "/stats": "Get dirty worker stats",
55 "/session/login?user_id=ID&name=NAME": "Login user (stash demo)",
56 "/session/get?user_id=ID": "Get session (stash demo)",
57 "/session/list": "List all sessions (stash demo)",
58 "/session/logout?user_id=ID": "Logout user (stash demo)",
59 "/session/stats": "Get stash stats (stash demo)",
60 }
61 }
62
63 elif path == '/models':
64 if client is None:
65 result = {"error": "Dirty workers not enabled"}
66 else:
67 result = client.execute(
68 "examples.dirty_example.dirty_app:MLApp",
69 "list_models"
70 )
71
72 elif path == '/load':
73 name = query.get('name', ['model1'])[0]
74 if client is None:
75 result = {"error": "Dirty workers not enabled"}
76 else:
77 result = client.execute(
78 "examples.dirty_example.dirty_app:MLApp",
79 "load_model",
80 name
81 )
82
83 elif path == '/inference':
84 model = query.get('model', ['default'])[0]
85 data = query.get('data', ['test input'])[0]
86 if client is None:
87 result = {"error": "Dirty workers not enabled"}

Callers 3

test_ml_appFunction · 0.70
test_compute_appFunction · 0.70
test_error_handlingFunction · 0.70

Calls 4

encodeMethod · 0.80
get_dirty_clientFunction · 0.70
getMethod · 0.45
executeMethod · 0.45

Tested by 3

test_ml_appFunction · 0.56
test_compute_appFunction · 0.56
test_error_handlingFunction · 0.56