Skip to content
Merged
Changes from all 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
7 changes: 4 additions & 3 deletions prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import socket
import time
import threading
from contextlib import closing

from . import core
try:
Expand Down Expand Up @@ -125,6 +126,6 @@ def _use_gateway(method, gateway, job, registry, grouping_key, timeout):

def instance_ip_grouping_key():
'''Grouping key with instance set to the IP Address of this host.'''
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('localhost', 0))
return {'instance': s.getsockname()[0]}
with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as s:
s.connect(('localhost', 0))
return {'instance': s.getsockname()[0]}