repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
gunicorn | examples/standalone_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python
#
# An example of a standalone application using the internal API of Gunicorn.
#
# $ python standalone_app.py
#
# This file is part of gunicorn released under the MIT license.
# See the NOTI... | 59 | 1,421 |
gunicorn | examples/alt_spec.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#
# An example of how to pass information from the command line to
# a WSGI app. Only applies to the native WSGI workers used by
# Gunicorn sync (default) workers.
#
# $ gunicorn 'alt_spec:load(arg)'
#
# Single q... | 28 | 822 |
gunicorn | examples/timeout.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import sys
import time
def app(environ, start_response):
"""Application which pauses 35 seconds before responding. the worker
will timeout in default case."""
data = b'Hello, World!\n'
status = '2... | 23 | 598 |
gunicorn | examples/bad.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import tempfile
files = []
def app(environ, start_response):
files.append(tempfile.mkstemp())
start_response('200 OK', [('Content-type', 'text/plain'), ('Content-length', '2')])
return ['ok']
| 11 | 310 |
gunicorn | examples/multiapp.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#
# Run this application with:
#
# $ gunicorn multiapp:app
#
# And then visit:
#
# http://127.0.0.1:8000/app1url
# http://127.0.0.1:8000/app2url
# http://127.0.0.1:8000/this_is_a_404
#
try:
from routes ... | 58 | 1,440 |
gunicorn | examples/slowclient.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import sys
import time
def app(environ, start_response):
"""Application which cooperatively pauses 10 seconds before responding"""
data = b'Hello, World!\n'
status = '200 OK'
response_headers = [
... | 22 | 582 |
gunicorn | examples/readline_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#
# Simple example of readline, reading from a stream then echoing the response
#
# Usage:
#
# Launch a server with the app in a terminal
#
# $ gunicorn -w3 readline_app:app
#
# Then in another terminal launch t... | 44 | 993 |
gunicorn | examples/longpoll.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import sys
import time
class TestIter:
def __iter__(self):
lines = [b'line 1\n', b'line 2\n']
for line in lines:
yield line
time.sleep(20)
def app(environ, start_resp... | 28 | 707 |
gunicorn | examples/multidomainapp.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import re
class SubDomainApp:
"""WSGI application to delegate requests based on domain name.
"""
def __init__(self, mapping):
self.mapping = mapping
def __call__(self, environ, start_response)... | 36 | 971 |
gunicorn | examples/log_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import logging
log = logging.getLogger(__name__)
log.addHandler(logging.StreamHandler())
def app_factory(global_options, **local_options):
return app
def app(environ, start_response):
start_response("20... | 21 | 478 |
gunicorn | examples/when_ready.conf.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import signal
import commands
import threading
import time
max_mem = 100000
class MemoryWatch(threading.Thread):
def __init__(self, server, max_mem):
super().__init__()
self.daemon = True
... | 42 | 1,126 |
gunicorn | examples/test.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#
# Example code from Eventlet sources
from wsgiref.validate import validator
from gunicorn import __version__
@validator
def app(environ, start_response):
"""Simplest possible application object"""
dat... | 27 | 637 |
gunicorn | examples/celery_alternative/app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Web Application - FastAPI app demonstrating Celery replacement.
This shows how to call dirty arbiter tasks from your web application
using the async API, which doesn't block the event loop.
Key difference fro... | 462 | 13,740 |
gunicorn | examples/celery_alternative/gunicorn_conf.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Gunicorn Configuration - Celery Replacement Example
This configuration sets up:
1. ASGI workers to handle web requests with async I/O (using uvloop)
2. Dirty workers to handle background tasks (replacing Celer... | 155 | 5,333 |
gunicorn | examples/celery_alternative/tasks.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Task Workers - Celery Replacement using Gunicorn Dirty Arbiters
This module demonstrates how to replace Celery with Gunicorn's dirty arbiter
feature for background task processing. Key benefits:
1. No externa... | 568 | 18,234 |
gunicorn | examples/celery_alternative/tests/test_tasks.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Unit Tests for Task Workers
These tests verify the task worker logic without running Gunicorn.
They test the DirtyApp classes directly.
"""
import pytest
from examples.celery_alternative.tasks import (
Em... | 309 | 10,322 |
gunicorn | examples/celery_alternative/tests/test_integration.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Integration Tests for Celery Replacement Example
These tests run against the full application with Gunicorn and dirty arbiters.
They can be run locally or in Docker.
Usage:
# Local (with gunicorn running)... | 436 | 13,489 |
gunicorn | examples/celery_alternative/tests/conftest.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Pytest configuration for Celery Replacement tests.
"""
import sys
from pathlib import Path
# Add gunicorn source to path for imports
gunicorn_root = Path(__file__).parent.parent.parent.parent
sys.path.insert(... | 15 | 343 |
gunicorn | examples/embedding_service/embedding_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from gunicorn.dirty.app import DirtyApp
class EmbeddingApp(DirtyApp):
def init(self):
from sentence_transformers import SentenceTransformer
self.model = SentenceTransformer('all-MiniLM-L6-v2')... | 19 | 476 |
gunicorn | examples/embedding_service/test_embedding.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import os
import requests
import numpy as np
def test_embedding_endpoint():
base_url = os.environ.get("EMBEDDING_SERVICE_URL", "http://127.0.0.1:8000")
url = f"{base_url}/embed"
# Test single text
... | 38 | 1,115 |
gunicorn | examples/embedding_service/main.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from fastapi import FastAPI
from pydantic import BaseModel
from gunicorn.dirty.client import get_dirty_client
app = FastAPI()
class EmbedRequest(BaseModel):
texts: list[str]
class EmbedResponse(BaseModel):... | 34 | 723 |
gunicorn | examples/embedding_service/gunicorn_conf.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
bind = "0.0.0.0:8000"
workers = 2
worker_class = "asgi"
# Dirty worker config
dirty_apps = ["embedding_service.embedding_app:EmbeddingApp"]
dirty_workers = 1
dirty_timeout = 60
| 13 | 284 |
gunicorn | examples/http2_features/test_http2.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python
"""
Test script for HTTP/2 features example.
This script tests:
- HTTP/2 connection establishment
- Stream priority access
- Response trailers
Run the server first:
docker compose up --b... | 296 | 8,843 |
gunicorn | examples/http2_features/gunicorn_conf.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# Gunicorn configuration for HTTP/2 features example
bind = "0.0.0.0:8443"
workers = 2
worker_class = "asgi"
# SSL configuration (required for HTTP/2)
certfile = "/app/certs/server.crt"
keyfile = "/app/certs/serv... | 25 | 535 |
gunicorn | examples/http2_features/http2_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
HTTP/2 ASGI application demonstrating priority and trailers.
This example shows how to:
- Access stream priority information from HTTP/2 requests
- Send response trailers (useful for gRPC, checksums, etc.)
Ru... | 271 | 8,660 |
gunicorn | examples/asgi/__init__.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
ASGI example applications for gunicorn.
"""
| 8 | 154 |
gunicorn | examples/asgi/websocket_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
WebSocket ASGI application example.
Run with:
gunicorn -k asgi examples.asgi.websocket_app:app
Test with:
# Using websocat (install with: cargo install websocat)
websocat ws://127.0.0.1:8000/ws
... | 236 | 6,927 |
gunicorn | examples/asgi/basic_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Basic ASGI application example.
Run with:
gunicorn -k asgi examples.asgi.basic_app:app
Test with:
curl http://127.0.0.1:8000/
curl http://127.0.0.1:8000/hello
curl -X POST http://127.0.0.1:800... | 131 | 3,949 |
gunicorn | examples/websocket/gevent_websocket.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import collections
import errno
import re
import hashlib
import base64
from base64 import b64encode, b64decode
import socket
import struct
import logging
from socket import error as SocketError
import gevent
from ... | 454 | 15,763 |
gunicorn | examples/http2_gevent/app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Example WSGI application demonstrating HTTP/2 with gevent worker.
This application showcases various HTTP/2 features including:
- Basic request/response handling
- Large file transfers (streaming)
- Concurrent... | 135 | 4,162 |
gunicorn | examples/http2_gevent/gunicorn_conf.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Gunicorn configuration for HTTP/2 with gevent worker.
This configuration demonstrates:
- HTTP/2 protocol support with ALPN
- Gevent async worker for high concurrency
- SSL/TLS configuration
- HTTP/2 specific t... | 85 | 2,683 |
gunicorn | examples/http2_gevent/test_http2_gevent.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python
"""
Tests for HTTP/2 with gevent example.
Run with:
# Start the server first
docker compose up -d
# Run tests
python test_http2_gevent.py
# Or with pytest
pytest tes... | 306 | 10,300 |
gunicorn | examples/streaming_chat/test_streaming.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""Integration tests for the streaming chat example."""
import json
import os
import requests
def test_health_endpoint():
"""Test the health check endpoint."""
base_url = os.environ.get("STREAMING_CHAT_U... | 154 | 4,619 |
gunicorn | examples/streaming_chat/chat_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import time
import random
from gunicorn.dirty.app import DirtyApp
class ChatApp(DirtyApp):
"""Simulated LLM chat application demonstrating streaming responses.
This app mimics LLM token-by-token generati... | 137 | 4,911 |
gunicorn | examples/streaming_chat/main.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import json
from fastapi import FastAPI
from fastapi.responses import StreamingResponse, HTMLResponse
from pydantic import BaseModel
from gunicorn.dirty.client import get_dirty_client_async
app = FastAPI(
tit... | 276 | 8,301 |
gunicorn | examples/streaming_chat/gunicorn_conf.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
bind = "0.0.0.0:8000"
workers = 2
worker_class = "asgi"
# Dirty worker config
dirty_apps = ["streaming_chat.chat_app:ChatApp"]
dirty_workers = 1
dirty_timeout = 60
| 13 | 271 |
gunicorn | examples/dirty_example/test_worker_integration.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python
"""
Integration test demonstrating DirtyWorker execution.
This test demonstrates how the DirtyWorker loads apps and handles requests
without actually forking processes (suitable for a quick t... | 278 | 8,671 |
gunicorn | examples/dirty_example/test_protocol.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python
"""
Test script to demonstrate the Dirty Binary Protocol layer.
The binary protocol uses a 16-byte header + TLV-encoded payloads for efficient
binary data transfer without base64 encoding ove... | 252 | 7,981 |
gunicorn | examples/dirty_example/wsgi_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Example WSGI Application that uses Dirty Workers
This demonstrates how HTTP workers can call dirty workers
for heavy operations like ML inference.
Run with:
cd examples/dirty_example
gunicorn wsgi_app... | 226 | 7,988 |
gunicorn | examples/dirty_example/test_integration.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python
"""
Integration test for the dirty example server.
This tests that the full gunicorn server with dirty workers responds
correctly to HTTP requests.
Run with:
python examples/dirty_exampl... | 82 | 2,180 |
gunicorn | examples/dirty_example/dirty_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Example Dirty Application - Simulates ML Model Loading and Inference
This demonstrates how to create a DirtyApp that:
1. Loads "models" at startup (init)
2. Handles requests from HTTP workers (__call__)
3. Cle... | 269 | 8,695 |
gunicorn | examples/dirty_example/gunicorn_conf.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Gunicorn configuration for Dirty Workers Example
Run with:
cd examples/dirty_example
gunicorn wsgi_app:app -c gunicorn_conf.py
"""
# Basic settings
# Use 0.0.0.0 for Docker, override with GUNICORN_BIN... | 63 | 1,449 |
gunicorn | examples/dirty_example/test_dirty_app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python
"""
Test script to demonstrate Dirty App functionality directly.
This tests the dirty app without running the full gunicorn server.
Run with:
python examples/dirty_example/test_dirty_app... | 165 | 4,030 |
gunicorn | examples/dirty_example/test_stash_integration.py | .py | #!/usr/bin/env python3
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Integration tests for stash (shared state) functionality.
These tests verify that stash works correctly across multiple dirty workers,
demonstrating that state is truly shared.
Run with... | 227 | 6,713 |
gunicorn | examples/frameworks/flaskapp_aiohttp_wsgi.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# Example command to run the example:
#
# $ gunicorn flaskapp_aiohttp_wsgi:aioapp -k aiohttp.worker.GunicornWebWorker
#
from aiohttp import web
from aiohttp_wsgi import WSGIHandler
from flask import Flask
app =... | 29 | 607 |
gunicorn | examples/frameworks/cherryapp.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import cherrypy
class Root:
@cherrypy.expose
def index(self):
return 'Hello World!'
cherrypy.config.update({'environment': 'embedded'})
app = cherrypy.tree.mount(Root())
| 16 | 296 |
gunicorn | examples/frameworks/pyramidapp.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('Hello world!')
def goodbye_world(request):
return Response('Goodbye world!')
confi... | 18 | 444 |
gunicorn | examples/frameworks/flaskapp.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# Run with:
#
# $ gunicorn flaskapp:app
#
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
| 16 | 253 |
gunicorn | examples/frameworks/tornadoapp.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#
# Run with:
#
# $ gunicorn -k tornado tornadoapp:app
#
import asyncio
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
async def get(self):
# Your asynchrono... | 34 | 644 |
gunicorn | examples/frameworks/flask_sendfile.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import io
from flask import Flask, send_file
app = Flask(__name__)
@app.route('/')
def index():
buf = io.BytesIO()
buf.write(b'hello world')
buf.seek(0)
return send_file(buf,
... | 19 | 397 |
gunicorn | examples/frameworks/webpyapp.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# Run with
#
# $ gunicorn webpyapp:app
#
import web
urls = (
'/', 'index'
)
class index:
def GET(self):
return "Hello, world!"
app = web.application(urls, globals()).wsgifunc()
| 21 | 303 |
gunicorn | examples/frameworks/django/testing/manage.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#!/usr/bin/env python
import os, sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testing.settings")
from django.core.management import execute_from_command_line
execut... | 14 | 350 |
gunicorn | examples/frameworks/django/testing/testing/wsgi.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
WSGI config for testing project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application`... | 39 | 1,465 |
gunicorn | examples/frameworks/django/testing/testing/settings.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# Django settings for testing project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.... | 177 | 5,836 |
gunicorn | examples/frameworks/django/testing/testing/apps/someapp/middleware.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from multiprocessing import Process, Queue
import requests
def child_process(queue):
while True:
print(queue.get())
requests.get('http://requestb.in/15s95oz1')
class GunicornSubProcessTestMi... | 28 | 725 |
gunicorn | examples/frameworks/django/testing/testing/apps/someapp/tests.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
fro... | 27 | 615 |
gunicorn | examples/frameworks/django/testing/testing/apps/someapp/views.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import csv
import io
import os
from django import forms
from django.http import HttpResponse
from django.shortcuts import render
from django.template import RequestContext
class MsgForm(forms.Form):
subject =... | 71 | 1,654 |
gunicorn | examples/frameworks/django/testing/testing/apps/someapp/urls.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^acsv$', views.acsv),
url(r'^$', views.home),
]
| 13 | 239 |
gunicorn | gunicorn/errors.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# We don't need to call super() in __init__ methods of our
# BaseException and Exception classes because we also define
# our own __str__ methods so there is no need to pass 'message'
# to the base class to get a m... | 29 | 897 |
gunicorn | gunicorn/util.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import ast
import email.utils
import errno
import fcntl
import html
import importlib
import inspect
import io
import logging
import os
import pwd
import random
import re
import socket
import sys
import textwrap
impo... | 695 | 20,487 |
gunicorn | gunicorn/__init__.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
version_info = (26, 0, 0)
__version__ = ".".join([str(v) for v in version_info])
SERVER = "gunicorn"
SERVER_SOFTWARE = "%s/%s" % (SERVER, __version__)
| 9 | 257 |
gunicorn | gunicorn/debug.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""The debug module contains utilities and functions for better
debugging Gunicorn."""
import sys
import linecache
import re
import inspect
__all__ = ['spew', 'unspew']
_token_spliter = re.compile(r'\W+')
clas... | 69 | 2,263 |
gunicorn | gunicorn/glogging.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import base64
import binascii
import json
import time
import logging
logging.Logger.manager.emittedNoHandlerWarning = 1 # noqa
from logging.config import dictConfig
from logging.config import fileConfig
import os
... | 484 | 15,569 |
gunicorn | gunicorn/sock.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import errno
import os
import socket
import ssl
import stat
import struct
import sys
import time
from gunicorn import util
PLATFORM = sys.platform
class BaseSocket:
def __init__(self, address, conf, log, f... | 316 | 9,295 |
gunicorn | gunicorn/reloader.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# pylint: disable=no-else-continue
import os
import os.path
import re
import sys
import time
import threading
COMPILED_EXT_RE = re.compile(r'py[co]$')
class ReloaderBase(threading.Thread):
def __init__(self,... | 129 | 3,736 |
gunicorn | gunicorn/pidfile.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import errno
import os
import tempfile
class Pidfile:
"""\
Manage a PID file. If a specific name is provided
it and '"%s.oldpid" % name' will be used. Otherwise
we create a temp file using os.mkst... | 88 | 2,381 |
gunicorn | gunicorn/config.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# Please remember to run "make -C docs html" after update "desc" attributes.
import argparse
import copy
import grp
import inspect
import ipaddress
import os
import pwd
import re
import shlex
import ssl
import sys... | 3,206 | 95,227 |
gunicorn | gunicorn/systemd.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import os
import socket
SD_LISTEN_FDS_START = 3
def listen_fds(unset_environment=True):
"""
Get the number of sockets inherited from systemd socket activation.
:param unset_environment: clear system... | 78 | 2,547 |
gunicorn | gunicorn/arbiter.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import errno
import os
import queue
import random
import signal
import sys
import time
import traceback
import socket
from gunicorn.errors import HaltServer, AppImportError
from gunicorn.pidfile import Pidfile
from... | 989 | 33,262 |
gunicorn | gunicorn/dirty/errors.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Dirty Arbiters Error Classes
Exception hierarchy for dirty worker pool operations.
"""
class DirtyError(Exception):
"""Base exception for all dirty arbiter errors."""
def __init__(self, message, det... | 181 | 6,401 |
gunicorn | gunicorn/dirty/app.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Dirty Application Base Class
Provides the DirtyApp base class that all dirty applications must inherit from,
and utilities for loading dirty apps from import paths.
"""
import importlib
import sys
from .erro... | 351 | 10,716 |
gunicorn | gunicorn/dirty/__init__.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Dirty Arbiters - Separate process pool for long-running operations.
Dirty Arbiters provide a separate process pool for executing long-running,
blocking operations (AI model loading, heavy computation) without ... | 82 | 2,017 |
gunicorn | gunicorn/dirty/tlv.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
TLV (Type-Length-Value) Binary Encoder/Decoder
Provides efficient binary serialization for dirty worker protocol messages.
Inspired by OpenBSD msgctl/msgsnd message format.
Type Codes:
0x00: None (no valu... | 304 | 10,428 |
gunicorn | gunicorn/dirty/stash.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Stash - Global Shared State for Dirty Workers
Provides simple key-value tables stored in the arbiter process.
All workers can read and write to the same tables.
Usage::
from gunicorn.dirty import stash
... | 504 | 13,582 |
gunicorn | gunicorn/dirty/protocol.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Dirty Worker Binary Protocol
Binary message framing over Unix sockets, inspired by OpenBSD msgctl/msgsnd.
Replaces JSON protocol for efficient binary data transfer.
Header Format (16 bytes):
+--------+-------... | 811 | 24,862 |
gunicorn | gunicorn/dirty/worker.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Dirty Worker Process
Asyncio-based worker that loads dirty apps and handles requests
from the DirtyArbiter.
Threading Model
---------------
Each dirty worker runs an asyncio event loop in the main thread for:... | 531 | 17,476 |
gunicorn | gunicorn/dirty/client.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Dirty Client
Client for HTTP workers to communicate with the dirty worker pool.
Provides both sync and async APIs.
"""
import asyncio
import contextvars
import os
import socket
import threading
import time
im... | 755 | 24,300 |
gunicorn | gunicorn/dirty/arbiter.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Dirty Arbiter Process
Asyncio-based arbiter that manages the dirty worker pool and routes
requests from HTTP workers to available dirty workers.
"""
import asyncio
import errno
import fnmatch
import os
import... | 1,153 | 41,576 |
gunicorn | gunicorn/http2/errors.py | .py | # -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
HTTP/2 specific exceptions.
These exceptions map to HTTP/2 error codes defined in RFC 7540.
"""
class HTTP2ErrorCode:
"""HTTP/2 Error Codes (RFC 7540 Section 7)."""
NO_ERROR = ... | 170 | 3,825 |
gunicorn | gunicorn/http2/request.py | .py | # -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
HTTP/2 request wrapper.
Provides a Request-compatible interface for HTTP/2 streams.
"""
from io import BytesIO
from gunicorn.util import split_request_uri
class HTTP2Body:
"""Body... | 235 | 6,488 |
gunicorn | gunicorn/http2/__init__.py | .py | # -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
HTTP/2 support for Gunicorn.
This module provides HTTP/2 protocol support using the hyper-h2 library.
HTTP/2 requires TLS with ALPN negotiation.
"""
H2_MIN_VERSION = (4, 1, 0)
_h2_avail... | 87 | 2,228 |
gunicorn | gunicorn/http2/async_connection.py | .py | # -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Async HTTP/2 server connection implementation for ASGI workers.
Uses the hyper-h2 library for HTTP/2 protocol handling with
asyncio for non-blocking I/O.
"""
import asyncio
from .errors... | 596 | 20,959 |
gunicorn | gunicorn/http2/connection.py | .py | # -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
HTTP/2 server connection implementation.
Uses the hyper-h2 library for HTTP/2 protocol handling.
"""
from io import BytesIO
from .errors import (
HTTP2Error, HTTP2ProtocolError, HTT... | 664 | 22,596 |
gunicorn | gunicorn/http2/stream.py | .py | # -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
HTTP/2 stream state management.
Each HTTP/2 stream represents a single request/response exchange.
"""
from enum import Enum, auto
from io import BytesIO
from .errors import HTTP2StreamE... | 365 | 10,993 |
gunicorn | gunicorn/http/parser.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import socket
import ssl
import time
from gunicorn.http.message import Request
from gunicorn.http.unreader import SocketUnreader, IterUnreader
# Cap on bytes drained from an unconsumed request body before a keep... | 122 | 4,274 |
gunicorn | gunicorn/http/wsgi.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import io
import logging
import os
import re
import sys
from gunicorn.http.message import TOKEN_RE
from gunicorn.http.errors import ConfigurationProblem, InvalidHeader, InvalidHeaderName
from gunicorn import SERVE... | 533 | 17,891 |
gunicorn | gunicorn/http/errors.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
# We don't need to call super() in __init__ methods of our
# BaseException and Exception classes because we also define
# our own __str__ methods so there is no need to pass 'message'
# to the base class to get a m... | 175 | 4,141 |
gunicorn | gunicorn/http/__init__.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from gunicorn.http.message import Message, Request
from gunicorn.http.parser import RequestParser
def get_parser(cfg, source, source_addr, http2_connection=False):
"""Get appropriate parser based on protocol ... | 37 | 1,162 |
gunicorn | gunicorn/http/message.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from enum import IntEnum
import ipaddress
import re
import socket
import struct
from gunicorn.http.body import ChunkedReader, LengthReader, EOFReader, Body
from gunicorn.http.errors import (
InvalidHeader, Inv... | 892 | 34,182 |
gunicorn | gunicorn/http/unreader.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import io
import os
# Classes that can undo reading data from
# a given type of data source.
class Unreader:
def __init__(self):
self.buf = io.BytesIO()
def chunk(self):
raise NotImpleme... | 81 | 1,971 |
gunicorn | gunicorn/http/body.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import io
import sys
from gunicorn.http.errors import (NoMoreData, ChunkMissingTerminator,
InvalidChunkSize, InvalidChunkExtension)
class ChunkedReader:
def __init__(self, r... | 272 | 7,787 |
gunicorn | gunicorn/asgi/parser.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
HTTP parser for ASGI workers.
Provides callback-based parsing using either the fast C parser (gunicorn_h1c)
or the pure Python PythonProtocol fallback.
"""
import socket
import struct
from enum import IntEnum... | 940 | 33,062 |
gunicorn | gunicorn/asgi/uwsgi.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""Async uWSGI protocol parser for ASGI workers.
Reuses the parsing logic from gunicorn/uwsgi/message.py, only async I/O differs.
"""
from gunicorn.uwsgi.message import UWSGIRequest
from gunicorn.uwsgi.errors imp... | 173 | 5,523 |
gunicorn | gunicorn/asgi/__init__.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
ASGI support for gunicorn.
This module provides native ASGI worker support, using gunicorn's own
HTTP parsing infrastructure adapted for async I/O.
Components:
- AsyncUnreader: Async socket reading with pushb... | 25 | 698 |
gunicorn | gunicorn/asgi/websocket.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
WebSocket protocol handler for ASGI.
Implements RFC 6455 WebSocket protocol for ASGI applications.
"""
import asyncio
import base64
import hashlib
import struct
# WebSocket frame opcodes
OPCODE_CONTINUATION... | 438 | 14,674 |
gunicorn | gunicorn/asgi/protocol.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
ASGI protocol handler for gunicorn.
Implements asyncio.Protocol to handle HTTP/1.x and HTTP/2 connections
and dispatch to ASGI applications.
"""
import asyncio
import errno
import ipaddress
import time
from ... | 1,791 | 70,068 |
gunicorn | gunicorn/asgi/unreader.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
Async version of gunicorn/http/unreader.py for ASGI workers.
Provides async reading with pushback buffer support.
"""
import io
class AsyncUnreader:
"""Async socket reader with pushback buffer support.
... | 136 | 4,121 |
gunicorn | gunicorn/asgi/lifespan.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"""
ASGI lifespan protocol manager.
Manages startup and shutdown events for ASGI applications,
enabling frameworks like FastAPI to run initialization and
cleanup code.
"""
import asyncio
class LifespanManager:
... | 179 | 6,275 |
gunicorn | gunicorn/instrument/statsd.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
"Bare-bones implementation of statsD's protocol, client-side"
import logging
import socket
from re import sub
from gunicorn.glogging import Logger
# Instrumentation constants
METRIC_VAR = "metric"
VALUE_VAR = "v... | 141 | 4,969 |
gunicorn | gunicorn/uwsgi/parser.py | .py | #
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from gunicorn.http.parser import Parser
from gunicorn.uwsgi.message import UWSGIRequest
class UWSGIParser(Parser):
"""Parser for uWSGI protocol requests."""
mesg_class = UWSGIRequest
| 13 | 300 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.