title: Stop spawned process from inherting bound port
body: <p>I'm writing a little HTTP server that spawns an VLC instance on request.
  However if I stop my server and try to restart it while the started VLC instance is still running it fails with <code>error: [Errno 48] Address already in use</code></p>
  
  <p>The server:</p>
  
  <pre><code>class Handler(BaseHTTPRequestHandler):
      def do_GET(self):
          vlcPort = 8191
          linkArg = "example.mp4"
          os.system('~/scripts/backVlcNoBorder.sh --http-port %s %s'%(vlcPort,linkArg))
  
  class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
      def server_bind(self):
          print "self.allow_reuse_address",self.allow_reuse_address
          self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
          self.socket.bind(self.server_address)
          # HTTPServer.server_bind(self)
  
  if __name__ == "__main__":
      server = ThreadingHTTPServer(("localhost",1111), Handler)
      server.serve_forever()
  </code></pre>
  
  <p>The script it calls to start VLC (~/scripts/backVlcNoBorder.sh)</p>
  
  <pre><code>#!/bin/bash
  nohup /Applications/VLC.app/Contents/MacOS/VLC $@ &gt;/dev/null 2&gt;/dev/null &amp;
  </code></pre>
  
  <p>If I make a request to the server, VLC starts.
  If I then shut down the server, but not VLC, and try to restart the server, it fails with:</p>
  
  <pre><code>self.allow_reuse_address 1
  Exception in thread Thread-1:
  Traceback (most recent call last):
    File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
      self.run()
    File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
      self.__target(*self.__args, **self.__kwargs)
    File "./http_request_server.py", line 263, in serve_on_port
      server = ThreadingHTTPServer(("localhost",1111), Handler)
    File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 420, in __init__
      self.server_bind()
    File "./http_request_server.py", line 256, in server_bind
      self.socket.bind(self.server_address)
    File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
      return getattr(self._sock,name)(*args)
  error: [Errno 48] Address already in use
  </code></pre>
  
  <p>After that I ran <code>lsof -n -i4TCP:1111 | grep LISTEN</code> to see whats still bound to 1111</p>
  
  <pre><code>bash    24365 admin    3u  IPv4 0x6d73e857a76dcad5      0t0  TCP 127.0.0.1:lmsocialserver (LISTEN)
  VLC     24366 admin    3u  IPv4 0x6d73e857a76dcad5      0t0  TCP 127.0.0.1:lmsocialserver (LISTEN)
  </code></pre>
  
  <p>I don't unterstand why both bash and VLC are listening to 1111, I guess it has to do with <code>os.system</code> with uses <code>fork()</code> maybe?</p>
  
  <p>How can I restart the server without having to shut down VLC, or how to I stop VLC from inherting the bound port?</p>
  
  <p>OS is Mac OSX 10.9</p>