title: OSError: [Errno 48] Address already in use
body: <p>I'm trying to setup a server from Mac terminal.</p>
  <p>I've established a connection on port 5000 and want to open another port in <code>5002</code> using this command:</p>
  <pre><code>python Blockchain.py -p 5002
  </code></pre>
  <p>But this gives the error:</p>
  <blockquote>
  <p>OSError: [Errno 48] Address already in use</p>
  </blockquote>
  <p>I tried to verify if port 5002 is open and listening. So I run
  shell command <code>lsof -i:5002</code> but it returns none.</p>
  <h3>Stacktrace</h3>
  <p>Error log &amp; stacktrace attached below:</p>
  <pre><code>Traceback (most recent call last):
   File &quot;Blockchain.py&quot;, line 290, in &lt;module&gt;
      app.run(host='0.0.0.0', port=5000)
    File &quot;/anaconda/envs/blockchain/lib/python3.6/site-packages/flask/app.py&quot;, line 841, in run
      run_simple(host, port, self, **options)
    File &quot;/anaconda/envs/blockchain/lib/python3.6/site-packages/werkzeug/serving.py&quot;, line 814, in run_simple
      inner()
    File &quot;/anaconda/envs/blockchain/lib/python3.6/site-packages/werkzeug/serving.py&quot;, line 774, in inner
      fd=fd)
    File &quot;/anaconda/envs/blockchain/lib/python3.6/site-packages/werkzeug/serving.py&quot;, line 666, in make_server
      passthrough_errors, ssl_context, fd=fd)
    File &quot;/anaconda/envs/blockchain/lib/python3.6/site-packages/werkzeug/serving.py&quot;, line 577, in __init__
      self.address_family), handler)
    File &quot;/anaconda/envs/blockchain/lib/python3.6/socketserver.py&quot;, line 453, in __init__
      self.server_bind()
    File &quot;/anaconda/envs/blockchain/lib/python3.6/http/server.py&quot;, line 136, in server_bind
      socketserver.TCPServer.server_bind(self)
    File &quot;/anaconda/envs/blockchain/lib/python3.6/socketserver.py&quot;, line 467, in server_bind
      self.socket.bind(self.server_address)
  OSError: [Errno 48] Address already in use
  </code></pre>
  <h3>Research</h3>
  <p>I've referred various answers on the same issue:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/19071512/socket-error-errno-48-address-already-in-use/19071568">socket.error: [Errno 48] Address already in use</a></li>
  <li><a href="https://stackoverflow.com/questions/23818572/flask-and-pycharm-socket-error">Flask and Pycharm socket.error</a></li>
  <li><a href="https://stackoverflow.com/questions/14765351/python-socket-error-address-in-use">Python - Socket Error, Address In Use</a></li>
  </ul>
  <h3>What I tried</h3>
  <p>Also, I tried the following methods to resolve the issue:</p>
  <ol>
  <li>Restarting the terminals</li>
  <li>Restarting PyCharm</li>
  <li>Running on different sockets (gives same error).</li>
  </ol>
  <p>None of that seems to work. I'm fairly new to Python.</p>
  <p>Any help is appreciated.</p>