Skip to content

Commit

Permalink
Merge pull request #47 from sfudeus/fix_threading
Browse files Browse the repository at this point in the history
Fix threading issue in 3.12 by explicitly keeping the main thread alive
  • Loading branch information
sfudeus authored Dec 23, 2023
2 parents b33c9db + ec2e882 commit 66f119c
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from http.server import HTTPServer
from pprint import pformat
import requests
from prometheus_client import Gauge, Counter, Enum, MetricsHandler, core, Summary
from prometheus_client import Gauge, Counter, Enum, MetricsHandler, core, Summary, start_http_server


class HomematicMetricsProcessor(threading.Thread):
Expand Down Expand Up @@ -368,14 +368,6 @@ class _ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
"""Thread per request HTTP server."""


def start_http_server(port, addr='', registry=core.REGISTRY):
"""Starts an HTTP server for prometheus metrics as a daemon thread"""
httpd = _ThreadingSimpleServer((addr, port), MetricsHandler.factory(registry))
thread = threading.Thread(target=httpd.serve_forever)
thread.daemon = False
thread.start()


if __name__ == '__main__':

PARSER = argparse.ArgumentParser()
Expand Down Expand Up @@ -418,3 +410,5 @@ def start_http_server(port, addr='', registry=core.REGISTRY):
# Start up the server to expose the metrics.
logging.info("Exposing metrics on port {}".format(ARGS.port))
start_http_server(int(ARGS.port))
# Wait until the main loop terminates
PROCESSOR.join()

0 comments on commit 66f119c

Please sign in to comment.