title: "RecursionError: maximum recursion depth exceeded in comparison" in async function
body: <p>I wrote a helper decorator for Tornado RequestHandler:</p>
  
  <pre><code>def return_response(method):
      @wraps(method)
      async def wrapper(self, *args, **kwargs):
          response = method(self, *args, **kwargs)
          if inspect.isawaitable(response):
              response = await response
          self.set_status(response.status)
          self.write(response.body)
      return wrapper
  </code></pre>
  
  <p>For some reason it fails with the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File ".../.venv/lib/python3.6/site-packages/tornado/web.py", line 1511, in _execute
      result = yield result
    File ".../.venv/lib/python3.6/site-packages/tornado/gen.py", line 1055, in run
      value = future.result()
    File ".../.venv/lib/python3.6/site-packages/tornado/concurrent.py", line 238, in result
      raise_exc_info(self._exc_info)
    File "&lt;string&gt;", line 4, in raise_exc_info
    File ".../.venv/lib/python3.6/site-packages/tornado/gen.py", line 307, in wrapper
      yielded = next(result)
    File "&lt;string&gt;", line 6, in _wrap_awaitable
    File ".../src/http_handlers/decorators.py", line 106, in wrapper
      response = await response
    File ".../src/http_handlers/decorators.py", line 106, in wrapper
      response = await response
    File ".../src/http_handlers/decorators.py", line 106, in wrapper
      response = await response
    [Previous line repeated 959 more times]
    File ".../src/http_handlers/decorators.py", line 104, in wrapper
      response = method(self, *args, **kwargs)
  RecursionError: maximum recursion depth exceeded in comparison
  </code></pre>
  
  <p>This error appeares only when the application is up for a while. Is it a bug in Python, Tornado or my code is wrong? Did somebody come across the same problem?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I've managed to solve the problem. It was in completely different place. I  used to apply this decorator at runtime in the <code>__new__</code> method. By mistake I was applying it to methods of the <code>cls</code>, not the actual instance. So methods were being wrapped again each time a new instance af a class was created.</p>