title: error 10055: 'no buffer space available' while populating database
body: <p>I am currently using python 3.4 and am getting an error 10055 when running my code. The code is below.</p>
  
  <p>I have tried putting a "time.sleep(10)" and it that allows my database to gather more entries, but eventually my program always gets the error. </p>
  
  <p>I understand that when I "sock.close()" my socket, the socket doesn't actually close, it lingers for a while before closing, and that is what is causing my error. </p>
  
  <p>I am unable to find a way to force the connection closed in order to free up sockets and run the program to completion. </p>
  
  <p>I have many methods in my code, but these are the ones that would be related to my errors, if you want the whole code, just let me know.</p>
  
  <pre><code>from urllib.request import urlopen
  import xml.etree.ElementTree as ET
  import time
  
  # Connect to MongoDB
  def database_connection():
      from pymongo import MongoClient
      MONGODB_HOST = 'localhost'
      MONGODB_PORT = 27017
      DBS_NAME = 'SEC'
      COLLECTION_NAME = 'Form15F'
      connection = MongoClient(MONGODB_HOST, MONGODB_PORT)
      collection = connection[DBS_NAME][COLLECTION_NAME]
      return collection, connection
  
  # Connection to the .XML online link
  def connection(xml_link):
      import socket
      # Make xml_link readable so it can be manipulated
      sock = urlopen(xml_link)
      xml_readable = sock.read()
      sock.close()
      root = ET.fromstring(xml_readable)
      return root
  
  # Populate database
  def database_addition(Holdings_FundName, Holdings_Name, Holdings_Shares, Holdings_Value, Holdings_Date):
      for i in range(len(Holdings_Name)):
          dictionary = {'Date':Holdings_Date[i] ,'Fund Name':Holdings_FundName[i],'Holding Company':Holdings_Name[i], 'Number of Shares':Holdings_Shares[i], 'Value of Shares':Holdings_Value[i]}
          db, dbc = database_connection()
          db.insert(dictionary)
          dbc.close()
  
  def main(link):
      all_xml_docs = fund_listings(link)
      for i in all_xml_docs:
          Fund_Name, date, xml_link = fund_details(i)
          print(Fund_Name)
          print(xml_link)
          Holdings_FundName, Holdings_Name, Holdings_Shares, Holdings_Value, Holdings_Date = holdings_attributes(xml_link, Fund_Name, date)
          database = database_addition(Holdings_FundName, Holdings_Name, Holdings_Shares, Holdings_Value, Holdings_Date)
          time.sleep(10)
  </code></pre>