Question: I'm running a web app with address 127.0.0.1:5000 and am using the python client library for Prometheus. I use `start_http_server(8000)` from the example in their [docs](https://github.com/prometheus/client_python) to expose the metrics on that port. The application runs, but I get `[Errno 48] Address already in use` and the localhost:8000 doesn't connect to anything when I try hitting it.

If I can't start two servers from one web app, then what port should I pass into `start_http_server()` in order to expose the metrics?

There is nothing already running on either port before I start the app.

Answer: 
Some other process is utilizing the port (8000). To kill the process that is running on the port (8000), simply find the process\_id [pid] of the process.

```
lsof -i :8000

```

This will show you the processes running on the port 8000 like this: 

```
COMMAND   PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
python3 21271 hashed    3u  IPv4 1430288      0t0  TCP *:8000 (LISTEN)

```

You can kill the process using the kill command like this:

```
sudo kill -9 21271

```

Recheck if the process is killed using the same command

```
lsof -i :8000

```

There should be nothing on the stdout.
This is mainly because you are restarting the server again on the port 8000.

To resolve this I created a function which will create the server after assuring the previous server or the port can be used. 

You can look at <https://github.com/prometheus/client_python/issues/155>, here the same case is addressed