-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
make Sanic.create_server return an asyncio.Server #1470
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3916392
make Sanic.create_server return an asyncio.Server
denismakogon 2cb05ab
More tests, attempting to fix CI
denismakogon b89c533
Adding doc
denismakogon 0242bc9
Fix type asserting
denismakogon eed22a7
Fix app.create_server calls
denismakogon 7579747
skip tests if python version is not 3.7 at least
denismakogon 1af1683
make tests dependent on uvloop
denismakogon f8f0241
refactor uvloop detection in its own method
denismakogon b36bd21
fix uvloop check
denismakogon 1473753
linter fix
denismakogon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Python 3.7 AsyncIO examples | ||
########################### | ||
|
||
With Python 3.7 AsyncIO got major update for the following types: | ||
|
||
- asyncio.AbstractEventLoop | ||
- asyncio.AnstractServer | ||
|
||
|
||
This example shows how to use sanic with Python 3.7, to be precise: how to retrieve an asyncio server instance: | ||
|
||
.. code:: python | ||
|
||
import asyncio | ||
import socket | ||
import os | ||
|
||
from sanic import Sanic | ||
from sanic.response import json | ||
|
||
app = Sanic(__name__) | ||
|
||
|
||
@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.remote(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_args=dict( | ||
start_serving=False | ||
) | ||
) | ||
srv = loop.run_until_complete(srv_coro) | ||
try: | ||
assert srv.is_serving() is False | ||
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() | ||
|
||
|
||
Please note that uvloop does not support these features yet. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:
AbstractServer