title: segmentation fault in python3
body: <p>I am running python3 on a Ubuntu machine and have noticed that the following block of code is fickle. Sometimes it runs just fine, other times it produces a segmentation fault. I don't understand why. Can someone explain what might be going on?</p>
  
  <p>Basically what the code does is try to read S&amp;P companies from Wikipedia and write the list of tickers to a file in the same directory as the script. If no connection to Wikipedia can be established, the script tries instead to read an existing list from file. </p>
  
  <pre><code>from urllib import request
  from urllib.error import URLError
  from bs4 import BeautifulSoup
  import os
  import pickle
  import dateutil.relativedelta as dr
  import sys
  
  sys.setrecursionlimit(100000)
  
  def get_standard_and_poors_500_constituents():
      fname = (
          os.path.abspath(os.path.dirname(__file__)) + "/sp500_constituents.pkl"
      )
      try:
          # URL request, URL opener, read content.
          req = request.Request(
              "http://en.wikipedia.org/wiki/List_of_S%26P_500_companies"
          )
          opener = request.urlopen(req)
          # Convert bytes to UTF-8.
          content = opener.read().decode()
          soup = BeautifulSoup(content, "lxml")
          # HTML table we actually need is the first.
          tables = soup.find_all("table")     
          external_class = tables[0].findAll("a", {"class":"external text"})
          c = [ext.string for ext in external_class if not "reports" in ext]
  
          with open(fname, "wb") as f:
              pickle.dump(c, f)
  
      except URLError:
          with open(fname, "rb") as f:
              c = pickle.load(f)
      finally:
          return c
  
  
  sp500_constituents = get_standard_and_poors_500_constituents()
  spdr_etf = "SPY"
  sp500_index = "^GSPC"
  
  def main():
      X = get_standard_and_poors_500_constituents()
      print(X)
  
  if __name__ == "__main__":
      main()
  </code></pre>