[Tutor] asyncio and wsgiref problem
Etienne Robillard
tkadm30 at yandex.com
Thu Nov 9 13:29:17 EST 2017
OK i figured that wsgiref (PEP-3333) is currently incompatible with
asyncio. I'm not sure about the motivations of this incompatibility.
Would it be so hard to make a "wsgiref.asyncio_server" extension for
people wanting to use wsgiref for development without having to use a
third-party extension?
Anyways, I'm now using uWSGI for development and testing.
Etienne
Le 2017-11-08 à 15:30, Etienne Robillard a écrit :
> 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
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
--
Etienne Robillard
tkadm30 at yandex.com
http://www.isotopesoftware.ca/
More information about the Tutor
mailing list