Skip to content
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

Please return thread from start_http_server #883

Closed
lukeyeager opened this issue Jan 23, 2023 · 6 comments · Fixed by #999
Closed

Please return thread from start_http_server #883

lukeyeager opened this issue Jan 23, 2023 · 6 comments · Fixed by #999

Comments

@lukeyeager
Copy link

Similar to #314, but less invasive, IMHO.

I often wrap APIs with a small layer of Python to turn metrics into something that Prometheus can ingest. Rather than adding while True: sleep(1) or similar at the end of my scripts I would like to do this:

prometheus_client.REGISTRY.register(MyCollector())
thread = prometheus_client.start_http_server(80)
thread.join()
@lukeyeager lukeyeager changed the title Return thread from start_http_server Please return thread from start_http_server Jan 23, 2023
@csmarchbanks
Copy link
Member

csmarchbanks commented Jan 23, 2023

I think I would be ok with this but will give a bit of time for others to chime in as well. My only initial concern would be that it would make it a bit harder to change an internal implementation, but that is fairly minor.

@hholst80
Copy link

I was thinking about this. How do I shut down the serving component? I guess I don't and just shutdown the application.

@csmarchbanks
Copy link
Member

Correct, start_http_server is designed to be as simple as possible for use cases such as a lightweight exporter. If additional functionality is required it is encouraged to use a different server.

@hholst80
Copy link

hholst80 commented Feb 8, 2023

I am in favor of a way to control with the thing created. Having a start_http_server not returning a handle is like a copy command that copies files but doesn't tell you where it put the file copy and now it's a game of hide and seek. ;-)

@andy-maier
Copy link
Contributor

We would also like to have that, see issue #983.

@csmarchbanks
Copy link
Member

#999 will implement this. It returns the server as well as the thread to allow shutdowns, happy to hear any comments about that and will otherwise merge it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants