Skip to content

Commit

Permalink
Signals Integration (#2160)
Browse files Browse the repository at this point in the history
* Update some tests

* Resolve #2122 route decorator returning tuple

* Use rc sanic-routing version

* Update unit tests to <:str>

* Minimal working version with some signals implemented

* Add more http signals

* Update ASGI and change listeners to signals

* Allow for dynamic ODE signals

* Allow signals to be stacked

* Begin tests

* Prioritize match_info on keyword argument injection

* WIP on tests

* Compat with signals

* Work through some test coverage

* Passing tests

* Post linting

* Setup proper resets

* coverage reporting

* Fixes from vltr comments

* clear delayed tasks

* Fix bad test

* rm pycache
  • Loading branch information
ahopkins authored Aug 5, 2021
1 parent 0ba57d4 commit b1b12e0
Show file tree
Hide file tree
Showing 31 changed files with 819 additions and 509 deletions.
29 changes: 22 additions & 7 deletions examples/run_async_advanced.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
from sanic import Sanic
from sanic import response
from signal import signal, SIGINT
import asyncio

from signal import SIGINT, signal

import uvloop

from sanic import Sanic, response
from sanic.server import AsyncioServer


app = Sanic(__name__)

@app.listener('after_server_start')

@app.listener("after_server_start")
async def after_start_test(app, loop):
print("Async Server Started!")


@app.route("/")
async def test(request):
return response.json({"answer": "42"})


asyncio.set_event_loop(uvloop.new_event_loop())
serv_coro = app.create_server(host="0.0.0.0", port=8000, return_asyncio_server=True)
serv_coro = app.create_server(
host="0.0.0.0", port=8000, return_asyncio_server=True
)
loop = asyncio.get_event_loop()
serv_task = asyncio.ensure_future(serv_coro, loop=loop)
signal(SIGINT, lambda s, f: loop.stop())
server = loop.run_until_complete(serv_task)
server: AsyncioServer = loop.run_until_complete(serv_task) # type: ignore
server.startup()

# When using app.run(), this actually triggers before the serv_coro.
# But, in this example, we are using the convenience method, even if it is
# out of order.
server.before_start()
server.after_start()
try:
loop.run_forever()
except KeyboardInterrupt as e:
except KeyboardInterrupt:
loop.stop()
finally:
server.before_stop()
Expand Down
Loading

0 comments on commit b1b12e0

Please sign in to comment.