title: I'm still getting error of recursion in python: memory error stack overflow
body: <p>Me And My friends Are working on a project in python.We coding some that every emails sent on an inbox he search on a list and if he find on the list,script execute some action on a web site.
  The Problem is that when we run the script after some time we get recursion error of stack!
  we modified the code for increasing in this way adding <code>sys.setrecursionlimit(sys.getrecursionlimit() + 100)</code> but after many hours script gives: <strong>Memory error!Stack Overflow</strong>!</p>
  
  <p>This is the entire script code:</p>
  
  <pre><code>
  import zmail
  import time
  import gspread
  from oauth2client.service_account import ServiceAccountCredentials
  from selenium import webdriver
  from selenium.common.exceptions import NoSuchElementException
  
  server = zmail.server('EMAIL', 'PASSWORD')
  options = webdriver.ChromeOptions()
  options.add_argument("start-maximized")
  options.add_argument('disable-infobars')
  scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
  creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
  client = gspread.authorize(creds)
  
  
  sheet = client.open("SHEET LIST").sheet1
  #sheet.update_cell(1, 6, "Error!")
  
  
  def check():
     sair = False
     mailbox_info = server.stat()
     sys.setrecursionlimit(sys.getrecursionlimit() + 100)
     if mailbox_info[0] &gt; 0:
         total = mailbox_info[0]
         for x in range(0, total):
             #print(x)
             body = server.get_mail(total - x)
             body = body['content_text']
             body = str(body)
             print(body)
             row = len(sheet.col_values(1))
             emails = sheet.col_values(1)
             passwords = sheet.col_values(2)
             keys = sheet.col_values(4)
             contador = 0
             while sair == False:
                 #print(row)
                 #print(contador)
                 if body.find(str(emails[contador])) != -1:
                     #print("if")
                     f = open("log.txt", "a")
                     email = str(emails[contador])
                     passw = str(passwords[contador])
                     key = str(keys[contador])
                     print("Found this email " + email)
                     f.write("Found this email " + email + "\n")
                     driver = webdriver.Chrome(options=options)
                     try:
                         driver.get("WEBSITE FOR DOING ACTION")
                     except:
                         sheet.update_cell(contador + 1, 6, "Error!")
                         sair = True
                     email_in = driver.find_element_by_xpath("/html/body/div/div[2]/div/div[3]/input")
                     email_in.send_keys(email)
                     print("Writing email...")
                     f.write("Writing email... \n")
                     password_in = driver.find_element_by_xpath("/html/body/div/div[2]/div/div[4]/input")
                     password_in.send_keys(passw)
                     print("Writing password...")
                     f.write("Writing password... \n")
                     key_in = driver.find_element_by_xpath("/html/body/div/div[2]/div/div[6]/input")
                     key_in.send_keys(key)
                     print("Writing key...")
                     f.write("Writing key... \n")
                     checkbox_in = driver.find_element_by_xpath("/html/body/div/div[2]/div/div[2]/label[2]/input")
                     driver.execute_script("arguments[0].click();", checkbox_in)
                     print("Selecting checkbox...")
                     f.write("Selecting checkbox... \n")
                     button_in = driver.find_element_by_xpath("/html/body/div/div[2]/div/div[8]")
                     print("Clicking button...")
                     f.write("Clicking button... \n")
                     driver.execute_script("arguments[0].click();", button_in)
                     time.sleep(120)
                     if driver.find_element_by_xpath("/html/body/div/div[2]/div/div[1]/p[2]").is_displayed():
                         sheet.update_cell(contador + 1, 6, "Success!")
                     else:
                         sheet.update_cell(contador + 1, 6, "Error!")
                     driver.close()
                     contador += 1
                     if contador &gt;= row:
                         sair = True
                     #sair = True
                 else:
                     #print("else")
                     contador += 1
                     if contador &gt;= row:
                         sair = True
             contador = 0
             timeC()
  
     else:
         timeC()
  
  
  def timeC():
     time.sleep(10) ```
  
  </code></pre>
  
  <p>But i know the error is in this part of code    </p>
  
  <pre><code> timeC()
  
      else:
          timeC()
  
  def timeC():
      time.sleep(10) 
  check()
  
  
  timeC()
  </code></pre>
  
  <p><strong>How We Can Resolve Guys?</strong></p>
  
  <p>This is traceback with recursion limit outside of the check:</p>
  
  <pre><code>File "main.py", line 100, in timeC
      check()
    File "main.py", line 95, in check
      timeC()
    File "main.py", line 100, in timeC
      check()
    File "main.py", line 95, in check
      timeC()
    File "main.py", line 100, in timeC
      check()
    File "main.py", line 95, in check
      timeC()
    File "main.py", line 100, in timeC
      check()
    File "main.py", line 95, in check
      timeC()
    File "main.py", line 100, in timeC
      check()
    File "main.py", line 95, in check
      timeC()
    File "main.py", line 100, in timeC
      check()
    File "main.py", line 95, in check
      timeC()
    File "main.py", line 100, in timeC
      check()
    File "main.py", line 25, in check
      mailbox_info = server.stat()
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\zmail\server.py", line 129, in stat
      with self.pop_server as server:
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\zmail\abc.py", line 78, in __enter__
      self.login()
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\zmail\server.py", line 306, in login
      self._make_server()
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\zmail\server.py", line 290, in _make_server
      self.server = poplib.POP3_SSL(self.host, self.port, timeout=self.timeout)
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\poplib.py", line 447, in __init__
      POP3.__init__(self, host, port, timeout)
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\poplib.py", line 102, in __init__
      self.sock = self._create_socket(timeout)
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\poplib.py", line 450, in _create_socket
      sock = POP3._create_socket(self, timeout)
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\poplib.py", line 108, in _create_socket
      return socket.create_connection((self.host, self.port), timeout)
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 707, in create_connection
      for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 748, in getaddrinfo
      for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  RecursionError: encoding with 'idna' codec failed (RecursionError: maximum recursion depth exceeded in comparison)
  
  </code></pre>