-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPF error when using Asyncio server instance #49
Comments
This is very similar to this bug: ashleysommer/sanic-plugin-toolkit#12 This bug is triggered because starting Sanic in non-standard ways does not trigger the You can manually trigger the import asyncio
import socket
import os
from sanic import Sanic
from sanic.response import json
from sanic_cors import CORS
from spf import SanicPluginsFramework #<- this is added
app = Sanic(__name__)
spf = SanicPluginsFramework(app) #<- this is added
cors = spf.register_plugin(CORS) #<- this is changed
@app.route("/")
async def test(request):
return json({"hello": "world"})
server_socket = '/tmp/sanic.sock'
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
os.remove(server_socket)
finally:
sock.bind(server_socket)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
srv_coro = app.create_server(
sock=sock,
return_asyncio_server=True,
asyncio_server_kwargs=dict(
start_serving=False
)
)
srv = loop.run_until_complete(srv_coro)
try:
assert srv.is_serving() is False
spf._on_server_start(app, loop) #<- this is added
loop.run_until_complete(srv.start_serving())
assert srv.is_serving() is True
loop.run_until_complete(srv.serve_forever())
except KeyboardInterrupt:
srv.close()
loop.close() |
Thanks for your quick answer, really appreciated. Would you suggest that I add documentation about this use case in this project or in Sanic ? |
Documentation about this really should go in the Sanic Plugins Framework project. |
Following official documentation from Sanic , it is not possible to use CORS plugin with AsyncIO server instanciation.
Doing the following will provoke a crash, and server won't be able to process requests : "Error is SPF processing a request before App server is started."
The text was updated successfully, but these errors were encountered: