8000 Changes to allow each HTTP request to be a seperate thread by jamessewell · Pull Request #139 · prometheus/client_python · GitHub
[go: up one dir, main page]

Skip to content

Changes to allow each HTTP request to be a seperate thread #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions prometheus_client/exposition.py
Original file line number Diff line number Diff line 8000 change
Expand Up @@ -12,16 +12,16 @@

from . import core
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to change Python3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SocketServer import ThreadingMixIn
from urllib2 import build_opener, Request, HTTPHandler
from urllib import quote_plus
from urlparse import parse_qs, urlparse
except ImportError:
# Python 3
unicode = str
from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer
from http.server import BaseHTTPRequestHandler, HTTPServer
from socketserver import ThreadingMixIn
from urllib.request import build_opener, Request, HTTPHandler
from urllib.parse import quote_plus, parse_qs, urlparse

Expand Down Expand Up @@ -97,10 +97,13 @@ def log_message(self, format, *args):


def start_http_server(port, addr=''):
"""Spawns each HTTPServer in a new thread to prevent blocking."""
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
"""Starts a HTTP server for prometheus metrics as a daemon thread."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The daemon thread should be mentioned in start_http_server, as that's the primary docs the user will see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fixed

class PrometheusMetricsServer(threading.Thread):
def run(self):
httpd = HTTPServer((addr, port), MetricsHandler)
httpd = ThreadingSimpleServer((addr, port), MetricsHandler)
httpd.serve_forever()
t = PrometheusMetricsServer()
t.daemon = True
Expand Down
0