Search code examples
pythontornadopypy

Tornado on PyPy


I'm getting the following error message when trying to run my tornado server on pypy:

/pypy3-2.4.0-osx64/site-packages/pkg_resources/__init__.py:80: UserWarning: Support for Python 3.0-3.2 has been dropped. Future versions will fail here.

Does anyone know what this is talking about?

Also why does normal python interpreter allow the following function:

   @tornado.gen.coroutine
   def get(self,id):
      doc=[]
      cursor = self.c.find({"_id":id})

      while (yield cursor.fetch_next):
         doc.append(cursor.next_object())

      return doc

However pypy complains about using a return inside a generator. I did some reading and apparently the right way is to yield instead of return?

   @tornado.gen.coroutine
   def get(self,id):
      doc=[]
      cursor = self.c.find({"_id":id})

      while (yield cursor.fetch_next):
         doc.append(cursor.next_object())

      yield doc

I changed to yielding to get rid of the errors in pypy then went back to normal python and it crashed.


Solution

  • The current release of pypy3 is based on cpython 3.2. This is old enough that many packages have dropped support for it. Tornado doesn't support cpython 3.2 any more, but we do support pypy3 (the difference is the support for u"" unicode literals, which is present in pypy3 but wasn't re-added to cpython until 3.3).

    You cannot replace return with yield in a coroutine; this will raise a BadYieldError. Instead, you must replace return x with raise gen.Return(x). It wasn't possible to mix return and yield in the same function until python 3.3.