[Tutor] asyncio and wsgiref problem

Etienne Robillard tkadm30 at yandex.com
Wed Nov 8 15:30:56 EST 2017


This code is compatible with PEP-3333 on Python 3.5.3:

@asyncio.coroutine
def app(environ, start_response):
     try:
         result = (yield from AsyncIOController().application(environ, 
start_response))
     except:
         raise
     else:

         #XXX result is a generator. this should not be needed?

         yield from result

I updated my server code like so:

class AsyncIOController(WSGIController):
     def __init__(self, settings=None, executor=None, loop=None
         ):
         super(AsyncIOController, self).__init__(settings)
         # asyncio config.
         self._executor = executor
         self._loop = loop or get_event_loop()

     #@asyncio.coroutine
     def get_response(self, request=None, method='GET', data={}):
         response = super(AsyncIOController, self).get_response(request)
         return response

     @asyncio.coroutine
     def application(self, environ, start_response):
         with sessionmanager(environ):
             request.environ.update(environ)
             response = self.get_response(request=request)
         #assert isinstance(response, bytes), type(response)
         return response(environ, start_response)

     @asyncio.coroutine
     def __call__(self, environ, start_response, exc_info=None):
         result = self.application(environ, start_response)
         return result

How can i avoid calling "yield" twice in my test script ?

Thank you,

Etienne



More information about the Tutor mailing list