title: Python Multithreading - How to prevent None items from ending up in result - Concurrent Futures
body: <p>I am looking to scrape SSL data from a list of hostnames. Everything is working as expected, except that when the get_cert_data function returns None due to the absence of SSL cert or inability to connect to the host. The None value is appended to the certs_list either way. I am using a large list of 1 million hosts and I am expecting most of them to have no SSL certificate due to the nature of the data. Understandably I would like to save memory and not store 900K None values in a list. Thank you for taking the time to read this far! Bonus: Does it make more sense to use the domain name or hostname to obtain this data and why?</p>
  
  <pre><code>import concurrent.futures
  import pandas as pd
  
  df = pd.read_csv('hostnames.csv')
  hosts_list = df['Host name'].tolist()
  
  def get_cert_data(hostname):
      try:
          ctx = ssl.create_default_context()
          s = ctx.wrap_socket(socket.socket(), server_hostname=hostname)
          s.connect((hostname, 443))
          cert = s.getpeercert()
          issuer = dict(x[0] for x in cert['issuer'])
          issued_by = issuer['organizationName']
          if not "COMODO" in issued_by.upper():
              pass
          else:
              print(issued_by)
              return cert
      except Exception as e:
          pass
  
  with concurrent.futures.ThreadPoolExecutor(max_workers = 16) as pool:
      certs_list = list(pool.map(get_cert_data, hosts_list))
  </code></pre>