question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`@asyncio.coroutine` not running?

See original GitHub issue

Consider test_cy2.pyx:

import asyncio

loop = asyncio.get_event_loop()

async def handler():
    print('Before Sleep')
    await asyncio.sleep(1)
    print('After Sleep')
    return 1


async def run():
    print('Run started')
    res = await handler()
    assert res == 1
    print('Run ended')
    loop.stop()

loop.run_until_complete(asyncio.ensure_future(run()))
loop.run_forever()
$ python -c 'import os; import pyximport; pyximport.install(); os.chdir("/tmp"); import test_cy2'                                                                             features/aiohttp b6569d6 ✗
/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/Cython/Distutils/old_build_ext.py:30: UserWarning: Cython.Distutils.old_build_ext does not properly handle dependencies and is deprecated.
  "Cython.Distutils.old_build_ext does not properly handle dependencies "
Run started
Before Sleep
After Sleep
Run ended
$

Now consider test_cy3.pyx:

import asyncio


@asyncio.coroutine
def handler():
    print('Before Sleep')
    yield from asyncio.sleep(1)
    print('After Sleep')
    return 1


@asyncio.coroutine
def run():
    print('Run started')
    res = yield from handler()
    assert res == 1
    print('Run ended')
    loop.stop()

loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.ensure_future(run()))
loop.run_forever()
$ python -c 'import os; import pyximport; pyximport.install(); os.chdir("/tmp"); import test_cy3'                                                                             features/aiohttp b6569d6 ✗
/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/Cython/Distutils/old_build_ext.py:30: UserWarning: Cython.Distutils.old_build_ext does not properly han
dle dependencies and is deprecated.
  "Cython.Distutils.old_build_ext does not properly handle dependencies "
^CTraceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/pyximport/pyximport.py", line 445, in load_module
    language_level=self.language_level)
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/pyximport/pyximport.py", line 217, in load_module
    mod = imp.load_dynamic(name, so_path)
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
  File "test_cy3.pyx", line 22, in init test_cy3 (/home/vampas/.pyxbld/temp.linux-x86_64-3.5/pyrex/test_cy3.c:2118)
    loop.run_forever()
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/lib/python3.5/asyncio/base_events.py", line 345, in run_forever
    self._run_once()
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/lib/python3.5/asyncio/base_events.py", line 1276, in _run_once
    event_list = self._selector.select(timeout)
  File "/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/lib/python3.5/selectors.py", line 441, in select
    fd_event_list = self._epoll.poll(timeout, max_ev)
KeyboardInterrupt
$ 

I had to manually interrupt the loop and nothing ran…

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
s0undt3chcommented, Dec 14, 2016

So, I’ve been debugging my problem with no solution in sight but I have some test applications which do not corroborate with your first reply. The code can be found here, but basically(transcript of the repo’s readme file with the conclusions).

Versions Used

  • Python 3.5.2
  • Cython 0.25.1
  • aiohttp 1.1.6
  • aiohttp-session 0.8.0

testapp1

Run testapp1 in non compiled mode:


   python -c 'import testapp1.app'
   DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://localhost:8080 ========
  (Press CTRL+C to quit)

Now test the old and the new asyncio syntax handlers


   curl -sS http://localhost:8080/old && curl -sS http://localhost:8080/new
  OLD SYNTAX
  NEW SYNTAX

Now, let’s install testapp1 which will compile all code using cython:

   python setup.py install

  /home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/Cython/Distutils/old_build_ext.py:30: UserWarning: Cython.Distutils.old_build_ext does not properly han
  dle dependencies and is deprecated.
    "Cython.Distutils.old_build_ext does not properly handle dependencies "
  Compiling /home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/app.py because it changed.
  Compiling /home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/new_handlers.py because it changed.
  Compiling /home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/old_handlers.py because it changed.
  [1/3] Cythonizing /home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/app.py
  [2/3] Cythonizing /home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/new_handlers.py
  [3/3] Cythonizing /home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/old_handlers.py
  running install
  running bdist_egg
  running egg_info
  writing top-level names to testapp1.egg-info/top_level.txt
  writing testapp1.egg-info/PKG-INFO
  writing dependency_links to testapp1.egg-info/dependency_links.txt
  reading manifest file 'testapp1.egg-info/SOURCES.txt'
  writing manifest file 'testapp1.egg-info/SOURCES.txt'
  installing library code to build/bdist.linux-x86_64/egg
  running install_lib
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.5
  creating build/lib.linux-x86_64-3.5/testapp1
  copying testapp1/__init__.py -> build/lib.linux-x86_64-3.5/testapp1
  running build_ext
  building 'testapp1.app' extension
  creating build/temp.linux-x86_64-3.5
  creating build/temp.linux-x86_64-3.5/home
  creating build/temp.linux-x86_64-3.5/home/vampas
  creating build/temp.linux-x86_64-3.5/home/vampas/projects
  creating build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack
  creating build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console
  creating build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas
  creating build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features
  creating build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp
  creating build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios
  creating build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1
  creating build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1
  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/include/python3.5m -c /home/vampas/projects/Salt
  Stack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/app.c -o build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/app.o
  gcc -pthread -shared -L/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/lib build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/app.o -
  o build/lib.linux-x86_64-3.5/testapp1/app.cpython-35m-x86_64-linux-gnu.so
  building 'testapp1.new_handlers' extension
  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/include/python3.5m -c /home/vampas/projects/Salt
  Stack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/new_handlers.c -o build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1
  /new_handlers.o
  gcc -pthread -shared -L/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/lib build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/new_han
  dlers.o -o build/lib.linux-x86_64-3.5/testapp1/new_handlers.cpython-35m-x86_64-linux-gnu.so
  building 'testapp1.old_handlers' extension
  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/include/python3.5m -c /home/vampas/projects/Salt
  Stack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/old_handlers.c -o build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1
  /old_handlers.o
  gcc -pthread -shared -L/home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/lib build/temp.linux-x86_64-3.5/home/vampas/projects/SaltStack/console/raas/features/aiohttp/.scenarios/testapp-1/testapp1/old_han
  dlers.o -o build/lib.linux-x86_64-3.5/testapp1/old_handlers.cpython-35m-x86_64-linux-gnu.so
  creating build/bdist.linux-x86_64
  creating build/bdist.linux-x86_64/egg
  creating build/bdist.linux-x86_64/egg/testapp1
  copying build/lib.linux-x86_64-3.5/testapp1/app.cpython-35m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/testapp1
  copying build/lib.linux-x86_64-3.5/testapp1/__init__.py -> build/bdist.linux-x86_64/egg/testapp1
  copying build/lib.linux-x86_64-3.5/testapp1/old_handlers.cpython-35m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/testapp1
  copying build/lib.linux-x86_64-3.5/testapp1/new_handlers.cpython-35m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/testapp1
  byte-compiling build/bdist.linux-x86_64/egg/testapp1/__init__.py to __init__.cpython-35.pyc
  creating stub loader for testapp1/app.cpython-35m-x86_64-linux-gnu.so
  creating stub loader for testapp1/new_handlers.cpython-35m-x86_64-linux-gnu.so
  creating stub loader for testapp1/old_handlers.cpython-35m-x86_64-linux-gnu.so
  byte-compiling build/bdist.linux-x86_64/egg/testapp1/app.py to app.cpython-35.pyc
  byte-compiling build/bdist.linux-x86_64/egg/testapp1/new_handlers.py to new_handlers.cpython-35.pyc
  byte-compiling build/bdist.linux-x86_64/egg/testapp1/old_handlers.py to old_handlers.cpython-35.pyc
  creating build/bdist.linux-x86_64/egg/EGG-INFO
  copying testapp1.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
  copying testapp1.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  copying testapp1.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  copying testapp1.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
  copying testapp1.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
  creating 'dist/testapp1-0.0-py3.5-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
  removing 'build/bdist.linux-x86_64/egg' (and everything under it)
  Processing testapp1-0.0-py3.5-linux-x86_64.egg
  creating /home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/envs/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/testapp1-0.0-py3.5-linux-x86_64.egg
  Extracting testapp1-0.0-py3.5-linux-x86_64.egg to /home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/envs/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages
  Adding testapp1 0.0 to easy-install.pth file

  Installed /home/vampas/.dotfiles/.ext/pyenv/versions/3.5.2/envs/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/testapp1-0.0-py3.5-linux-x86_64.egg
  Processing dependencies for testapp1==0.0
  Finished processing dependencies for testapp1==0.0

And now, let’s run the compiled version of testapp1:


   cd /tmp && python -c 'import testapp1.app'
   DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://localhost:8080 ========
  (Press CTRL+C to quit)

Now test the old and the new asyncio syntax handlers:


   curl -sS http://localhost:8080/old && curl -sS http://localhost:8080/new

  <html>
    <head>
      <title>500 Internal Server Error</title>
    </head>
    <body>
      <h1>500 Internal Server Error</h1>
      Server got itself in trouble
    </body>
  </html>
  <html>
    <head>
      <title>500 Internal Server Error</title>
    </head>
    <body>
      <h1>500 Internal Server Error</h1>
      Server got itself in trouble
    </body>
  </html>

And the traceback on the server side:

  ERROR:aiohttp.web:Error handling request
  Traceback (most recent call last):
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/server.py", line 265, in start
      yield from self.handle_request(message, payload)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/web.py", line 96, in handle_request
      resp = yield from handler(request)
    File "/home/vampas/projects/SaltStack/console/asyncio/aiohttp-session/py35/aiohttp_session/__init__.py", line 130, in middleware
      raise RuntimeError("Expect response, not {!r}", type(response))
  RuntimeError: ('Expect response, not {!r}', <class 'generator'>)
  INFO:aiohttp.access:::1 - - [13/Dec/2016:13:42:37 +0000] "GET /old HTTP/1.1" 500 170 "-" "curl/7.51.0"
  ERROR:aiohttp.web:Error handling request
  Traceback (most recent call last):
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/server.py", line 265, in start
      yield from self.handle_request(message, payload)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/web.py", line 96, in handle_request
      resp = yield from handler(request)
    File "/home/vampas/projects/SaltStack/console/asyncio/aiohttp-session/py35/aiohttp_session/__init__.py", line 125, in middleware
      response = await handler(request)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/web_urldispatcher.py", line 113, in handler_wrapper
      result = yield from result
  TypeError: 'coroutine' object is not iterable
  INFO:aiohttp.access:::1 - - [13/Dec/2016:13:42:37 +0000] "GET /new HTTP/1.1" 500 170 "-" "curl/7.51.0"
  /home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/server.py:292: RuntimeWarning: coroutine 'new_handler' was never awaited
    yield from self.handle_error(500, message, None, exc)

testapp2

testapp2 just imports the inspect module in testapp2.app to try and trigger the cython asyncio patching.

Run testapp2 in non compiled mode:

   python -c 'import testapp2.app'
   DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://localhost:8080 ========
  (Press CTRL+C to quit)

Now test the old and the new asyncio syntax handlers

   curl -sS http://localhost:8080/old && curl -sS http://localhost:8080/new
  OLD SYNTAX
  NEW SYNTAX

And now, let’s run the compiled version of testapp2:

   cd /tmp && python -c 'import testapp2.app'
   DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://localhost:8080 ========
  (Press CTRL+C to quit)

Now test the old and the new asyncio syntax handlers:

   curl -sS http://localhost:8080/old && curl -sS http://localhost:8080/new

  <html>
    <head>
      <title>500 Internal Server Error</title>
    </head>
    <body>
      <h1>500 Internal Server Error</h1>
      Server got itself in trouble
    </body>
  </html>
  <html>
    <head>
      <title>500 Internal Server Error</title>
    </head>
    <body>
      <h1>500 Internal Server Error</h1>
      Server got itself in trouble
    </body>
  </html>

And the traceback on the server side:

  ERROR:aiohttp.web:Error handling request
  Traceback (most recent call last):
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/server.py", line 265, in start
      yield from self.handle_request(message, payload)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/web.py", line 96, in handle_request
      resp = yield from handler(request)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp_session/__init__.py", line 134, in middleware
      raise RuntimeError("Expect response, not {!r}", type(response))
  RuntimeError: ('Expect response, not {!r}', <class 'generator'>)
  INFO:aiohttp.access:::1 - - [13/Dec/2016:13:51:46 +0000] "GET /old HTTP/1.1" 500 170 "-" "curl/7.51.0"
  ERROR:aiohttp.web:Error handling request
  Traceback (most recent call last):
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/server.py", line 265, in start
      yield from self.handle_request(message, payload)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/web.py", line 96, in handle_request
      resp = yield from handler(request)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp_session/__init__.py", line 129, in middleware
      response = yield from handler(request)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/web_urldispatcher.py", line 113, in handler_wrapper
      result = yield from result
  TypeError: 'coroutine' object is not iterable
  INFO:aiohttp.access:::1 - - [13/Dec/2016:13:51:46 +0000] "GET /new HTTP/1.1" 500 170 "-" "curl/7.51.0"
  /home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/server.py:292: RuntimeWarning: coroutine 'new_handler' was never awaited
    yield from self.handle_error(500, message, None, exc)

testapp3

testapp3 just imports the inspect module on the request handlers modules to try and trigger the cython asyncio patching.

Run testapp3 in non compiled mode:

   python -c 'import testapp3.app'
   DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://localhost:8080 ========
  (Press CTRL+C to quit)

Now test the old and the new asyncio syntax handlers

   curl -sS http://localhost:8080/old && curl -sS http://localhost:8080/new
  OLD SYNTAX
  NEW SYNTAX

And now, let’s run the compiled version of testapp3:

   cd /tmp && python -c 'import testapp3.app'
   DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://localhost:8080 ========
  (Press CTRL+C to quit)

Now test the old and the new asyncio syntax handlers:

   curl -sS http://localhost:8080/old && curl -sS http://localhost:8080/new
   OLD SYNTAX

  <html>
    <head>
      <title>500 Internal Server Error</title>
    </head>
    <body>
      <h1>500 Internal Server Error</h1>
      Server got itself in trouble
    </body>
  </html>

And the traceback on the server side:

  INFO:aiohttp.access:::1 - - [13/Dec/2016:13:57:57 +0000] "GET /old HTTP/1.1" 200 12 "-" "curl/7.51.0"
  ERROR:aiohttp.web:Error handling request
  Traceback (most recent call last):
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/server.py", line 265, in start
      yield from self.handle_request(message, payload)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/web.py", line 96, in handle_request
      resp = yield from handler(request)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp_session/__init__.py", line 129, in middleware
      response = yield from handler(request)
    File "/home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/web_urldispatcher.py", line 113, in handler_wrapper
      result = yield from result
  TypeError: 'coroutine' object is not iterable
  INFO:aiohttp.access:::1 - - [13/Dec/2016:13:57:57 +0000] "GET /new HTTP/1.1" 500 170 "-" "curl/7.51.0"
  /home/vampas/.dotfiles/.ext/pyenv/versions/Raas-3.5.2-features-aiohttp/lib/python3.5/site-packages/aiohttp/server.py:292: RuntimeWarning: coroutine 'new_handler' was never awaited
    yield from self.handle_error(500, message, None, exc)

testapp4

testapp4 decorates the new async def syntax handler with @asyncio.coroutine:

Run testapp4 in non compiled mode:

   python -c 'import testapp4.app'
   DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://localhost:8080 ========
  (Press CTRL+C to quit)

Now test the old and the new asyncio syntax handlers

   curl -sS http://localhost:8080/old && curl -sS http://localhost:8080/new
  OLD SYNTAX
  NEW SYNTAX

And now, let’s run the compiled version of testapp4:

   cd /tmp && python -c 'import testapp4.app'
   DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://localhost:8080 ========
  (Press CTRL+C to quit)

Now test the old and the new asyncio syntax handlers:

   curl -sS http://localhost:8080/old && curl -sS http://localhost:8080/new
  OLD SYNTAX
  NEW SYNTAX

On this testapp4 we can safely remove the inspect import from the module where the aiohttp web application is setup but not from any of the handlers.

0reactions
scodercommented, Dec 10, 2016

“Yeah, if we use 3rd party libs which use the asyncio.coroutine, we’re still stuck” It’s (usually) enough if one of the Cython modules in the system imports these modules in order to activate the inspect integration, as all modules built with the same Cython version will share the same internal type implementation.

“This example is to mimic someone using the 3.5 async def/await syntax while having to work with libraries with pre 3.5 syntax…” Note that you can use async/await in Cython modules even if the Python runtime does not support it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Asyncio is not running new coroutine ... - Stack Overflow
1>Python Asyncio is not running new coroutine using asyncio.run_coroutine_threadsafe. Below is the code testing performed on Mac.
Read more >
Coroutines and Tasks — Python 3.11.1 documentation
To actually run a coroutine, asyncio provides the following mechanisms: ... The asyncio.create_task() function to run coroutines concurrently as asyncio Tasks .
Read more >
How to Run an Asyncio Coroutine in Python
You can run an asyncio coroutine via the run() function, by awaiting it within another coroutine, or by scheduling it as Task.
Read more >
Common Mistakes Using Python3 asyncio
Common Mistakes Using Python3 asyncio · 1. Introduction · 2. RuntimeWarning: coroutine foo was never awaited · 3. Task was destroyed but it...
Read more >
9.4. AsyncIO Coroutine - Python
9.4.8. Error: Running Coroutine Functions¶. Only coroutine objects can be run. It is not possible to run coroutine function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found