Python Forum
Wsgiref with asyncio ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wsgiref with asyncio ?
#6
I am not familiar with the plain WSGI at all. Never used directly. So I can only guess how it works.

But first something about asycnio.

run_until_complete returns the result of a future object ( maincoro ) - in that case it will be [str('Test of requisition http ?').encode('utf-8')]. Which is a list BTW. The returned result will be the returned one from the coroutine ( maincoro ) object. It does not return a callable function which you can use into the with statement.

I think make_server runs the server and waits for a request. Then when happens it calls the hander ( maincoro is your handler ) and its returned object is sent back. Instead of giving it a function to execute on a request, you are giving it [str('Test of requisition http ?').encode('utf-8')] .

The error is because maincoro is executed before the with statement which takes the request and provides the environ as an argument to maincoro. The environ object doesn't exist yet at the execution of maincoro.

I guess you are not quite familiar how asyncio and the event loop work.

asyncio is not a small library. I barely touch it sometimes. When I need some async calls. Most of the time I use 3rd party libraries to do web requests for example. Lke aiohttp or httpx... One may call them frameworks. Anyway.

During figuring out for myself what is going on with such a low-level library as WSGI I came across two I think useful web pages. First is how to make a framework using WSGI. Perhaps it explains a lot of its machinery. I don't have time to dig into it.

The second one is about asynchronous WSGI called ASGI which I think you can use for your purposes. Making an asynchronous framework using a low-level library. At least you will be able to see how they wrap WSGI in order to work with asyncio.

Apologize my English Wink
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
Wsgiref with asyncio ? - by JohnnyCoffee - Oct-27-2022, 06:59 PM
RE: Wsgiref with asyncio ? - by wavic - Oct-28-2022, 11:17 AM
RE: Wsgiref with asyncio ? - by JohnnyCoffee - Oct-28-2022, 02:12 PM
RE: Wsgiref with asyncio ? - by wavic - Oct-28-2022, 02:59 PM
RE: Wsgiref with asyncio ? - by JohnnyCoffee - Oct-30-2022, 10:36 PM
RE: Wsgiref with asyncio ? - by wavic - Oct-31-2022, 02:50 AM
RE: Wsgiref with asyncio ? - by JohnnyCoffee - Oct-31-2022, 03:42 PM
RE: Wsgiref with asyncio ? - by wavic - Oct-31-2022, 03:47 PM
RE: Wsgiref with asyncio ? - by JohnnyCoffee - Nov-01-2022, 08:35 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020