Oct-30-2022, 10:36 PM
(Oct-28-2022, 02:59 PM)wavic Wrote: Maybe this could give you some directions.
Note that the syntax for making a coroutine is async def/await now. That one there was the old way. Using a decorator...
You are awaiting instead of yield from
I managed to define a simple and very logical implementation, but I come across the following error:
# Native Module : wsgiref.simple_server -> ( https://docs.python.org/3/library/wsgiref.html#module-wsgiref ) from wsgiref.simple_server import make_server # Native Module : asyncio — Asynchronous I/O -> https://docs.python.org/3/library/asyncio.html#module-asyncio from asyncio import get_event_loop # Function -> define coroutine, to run the function asynchronous async def maincoro(environ, start_response): status = '200 OK' # HTTP Status headers = [('Content-type', 'text/plain; charset=utf-8')] # HTTP Headers start_response(status, headers) # The returned object is going to be printed return [str('Test of requisition http ?').encode('utf-8')] # Function -> prepare a loop to work with asynchronous events ( request list ) : loop = get_event_loop() # Function -> run the loop until finished : coro = loop.run_until_complete(maincoro(environ, start_response)) with make_server('', 8000, coro) as httpd: print('Serving on port 8000...') # Serve until process is killed httpd.serve_forever()
Error : (wse) joe@debian:~/PycharmProjects/quark$ python trycode.py /home/joe/PycharmProjects/quark/trycode.py:31: DeprecationWarning: There is no current event loop loop = get_event_loop() Traceback (most recent call last): File "/home/joe/PycharmProjects/quark/trycode.py", line 33, in <module> coro = loop.run_until_complete(maincoro(environ, start_response)) NameError: name 'environ' is not defined