aiopyramid
aiopyramid copied to clipboard
aiostarter does not work
it seems like it's not picking up the settings in the development.ini but I dont know why that would be.
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid$ pipenv --python 3.7
Creating a virtualenv for this project…
Pipfile: /home/tom/projects/tstaiopyramid/Pipfile
Using /home/tom/.local-python/bin/python3.7 (3.7.7) to create virtualenv…
⠴ Creating virtual environment...Already using interpreter /home/tom/.local-python/bin/python3.7
Using base prefix '/usr'
New python executable in /home/tom/projects/tstaiopyramid/.venv/bin/python3.7
Also creating executable in /home/tom/projects/tstaiopyramid/.venv/bin/python
Installing setuptools, pip, wheel...
done.
✔ Successfully created virtual environment!
Virtualenv location: /home/tom/projects/tstaiopyramid/.venv
Creating a Pipfile for this project…
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid$ pipenv install aiopyramid[gunicorn] gunicorn
Installing aiopyramid[gunicorn]…
Adding aiopyramid to Pipfile's [packages]…
✔ Installation Succeeded
Installing gunicorn…
Adding gunicorn to Pipfile's [packages]…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (2db1e9)!
Installing dependencies from Pipfile.lock (2db1e9)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 22/22 — 00:00:01
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid$ pipenv run pcreate -s aio_starter tststarter
Note: As of Pyramid 1.8, this command is deprecated. Use a specific
cookiecutter instead:
https://github.com/pylons/?query=cookiecutter
Creating directory /home/tom/projects/tstaiopyramid/tststarter
Recursing into +package+
Creating /home/tom/projects/tstaiopyramid/tststarter/tststarter/
Copying __init__.py_tmpl to /home/tom/projects/tstaiopyramid/tststarter/tststarter/__init__.py
Copying tests.py_tmpl to /home/tom/projects/tstaiopyramid/tststarter/tststarter/tests.py
Copying views.py_tmpl to /home/tom/projects/tstaiopyramid/tststarter/tststarter/views.py
Copying CHANGES.rst_tmpl to /home/tom/projects/tstaiopyramid/tststarter/CHANGES.rst
Copying MANIFEST.in_tmpl to /home/tom/projects/tstaiopyramid/tststarter/MANIFEST.in
Copying README.rst_tmpl to /home/tom/projects/tstaiopyramid/tststarter/README.rst
Copying development.ini_tmpl to /home/tom/projects/tstaiopyramid/tststarter/development.ini
Copying setup.py_tmpl to /home/tom/projects/tstaiopyramid/tststarter/setup.py
===============================================================================
Tutorials: https://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/
Documentation: https://docs.pylonsproject.org/projects/pyramid/en/latest/
Twitter: https://twitter.com/PylonsProject
Mailing List: https://groups.google.com/forum/#!forum/pylons-discuss
Welcome to Pyramid. Sorry for the convenience.
===============================================================================
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid$ pipenv install -e tststarter/
Installing -e tststarter/…
Adding tststarter to Pipfile's [packages]…
✔ Installation Succeeded
Pipfile.lock (441085) out of date, updating to (2db1e9)…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (441085)!
Installing dependencies from Pipfile.lock (441085)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 23/23 — 00:00:02
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid$ cd tststarter/
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid/tststarter$ pipenv run gunicorn --paste development.ini
[2020-04-25 16:04:24 -0400] [29075] [INFO] Starting gunicorn 20.0.4
[2020-04-25 16:04:24 -0400] [29075] [INFO] Listening at: http://127.0.0.1:8000 (29075)
[2020-04-25 16:04:24 -0400] [29075] [INFO] Using worker: sync
[2020-04-25 16:04:24 -0400] [29084] [INFO] Booting worker with pid: 29084
[2020-04-25 16:04:41 -0400] [29084] [ERROR] Error handling request /
Traceback (most recent call last):
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/tweens.py", line 13, in _error_handler
response = request.invoke_exception_view(exc_info)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/view.py", line 779, in invoke_exception_view
raise HTTPNotFound
pyramid.httpexceptions.HTTPNotFound: The resource could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 134, in handle
self.handle_request(listener, req, client, addr)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/router.py", line 270, in __call__
response = self.execution_policy(environ, self)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/router.py", line 279, in default_execution_policy
return request.invoke_exception_view(reraise=True)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/view.py", line 778, in invoke_exception_view
reraise_(*exc_info)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/compat.py", line 179, in reraise
raise value
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/router.py", line 277, in default_execution_policy
return router.invoke_request(request)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/router.py", line 249, in invoke_request
response = handle_request(request)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/tweens.py", line 43, in excview_tween
response = _error_handler(request, exc)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/tweens.py", line 17, in _error_handler
reraise(*exc_info)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/compat.py", line 179, in reraise
raise value
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/tweens.py", line 41, in excview_tween
response = handler(request)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/router.py", line 148, in handle_request
registry, request, context, context_iface, view_name
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/view.py", line 667, in _call_view
response = view_callable(context, request)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/pyramid/viewderivers.py", line 436, in rendered_view
result = view(context, request)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/aiopyramid/config.py", line 27, in coroutine_view
return view(context, request)
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/aiopyramid/helpers.py", line 104, in _wrapped_coroutine
SCOPE_ERROR_MESSAGE.format(coroutine_func)
aiopyramid.exceptions.ScopeError:
Synchronized coroutine <function DefaultViewMapper.map_nonclass_requestonly.<locals>._requestonly_view at 0x7f58ca9d0ef0> called in the parent
greenlet.
This is most likely because you called the synchronized
coroutine inside of another coroutine. You need to
yield from the coroutine directly without wrapping
it in aiopyramid.helpers.synchronize.
If you are calling this coroutine indirectly from
a regular function and therefore cannot yield from it,
then you need to run the first caller inside a new
greenlet using aiopyramid.helpers.spawn_greenlet.
^C[2020-04-25 16:05:08 -0400] [29075] [INFO] Handling signal: int
[2020-04-25 16:05:08 -0400] [29084] [INFO] Worker exiting (pid: 29084)
[2020-04-25 16:05:08 -0400] [29075] [INFO] Shutting down: Master
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid/tststarter$
running pserve instead of gunicorn picks up the right worker and port from the config but then there's an import error
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid/tststarter$ pipenv run pserve development.ini
Starting server in PID 31751.
Error: class uri 'aiopyramid.gunicorn.worker.AsyncGunicornWorker' invalid or not found:
[Traceback (most recent call last):
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/gunicorn/util.py", line 99, in load_class
mod = importlib.import_module('.'.join(components))
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/aiopyramid/gunicorn/worker.py", line 3, in <module>
from aiohttp_wsgi.wsgi import WSGIHandler, ReadBuffer
ImportError: cannot import name 'ReadBuffer' from 'aiohttp_wsgi.wsgi' (/home/tom/projects/tstaiopyramid/.venv/lib/python3.7/site-packages/aiohttp_wsgi/wsgi.py)
]
Exiting 1 (-v to see traceback)
tom@tom-ThinkPad-P1:~/projects/tstaiopyramid/tststarter$
and checking the source code, ReadBuffer hasn't been in the wsgi module since 0.8.0 (march of 2018)
https://github.com/etianen/aiohttp-wsgi/compare/0.5.2...0.8.0
So what's going on here? is this still maintained? I know there's been a bit of churn in the past in regards to asyncio and probably aiohttp. But I just want to get websoockets working in pyramid.
Seems like gunicorn now essentially requires you to use pserve if you are going to use paste. https://docs.gunicorn.org/en/stable/run.html#paste-deployment. It will no longer respect the server definition from the paste config unless invoked with pserve:
but Gunicorn will not use any server configuration defined in the file
I was not able to replicate your import error, pserve worked for me. Have you tried configuring gunicorn separately?
The changes in gunicorn invalidate the getting started section of the docs as well as aiostarter
.
@housleyjk Hi Jason
Im dealing with the same error : class uri 'aiopyramid.gunicorn.worker.AsyncGunicornWorker' invalid or not found: Caused by: ImportError: cannot import name 'ReadBuffer' from 'aiohttp_wsgi.wsgi' (/home/xxxxx/xxxxxx/venv/lib/python3.7/site-packages/aiohttp_wsgi/wsgi.py)
Tried both with python 3.11 & 3.7 same issue.
After checking aiohttp-wsgi repo 'ReadBuffer' class seems to be missing, causing error when gunicorn start with:
worker_class = aiopyramid.gunicorn.worker.AsyncGunicornWorker
If used without worker class it works fine.
Last commit contained related class was : https://github.com/etianen/aiohttp-wsgi/commit/dd984417eacce2a52329db0440ce95ef294608d7
Any idea how to fix that ?