-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
DOCS: sync/async guide for sanic #2884
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2884 +/- ##
=========================================
Coverage 88.039% 88.039%
=========================================
Files 94 94
Lines 7433 7433
Branches 1283 1283
=========================================
Hits 6544 6544
Misses 622 622
Partials 267 267 ☔ View full report in Codecov by Sentry. |
def sync_print(text: str) -> None: | ||
rand_wait: int = randrange(0,5) | ||
time.sleep(rand_wait) | ||
print(f'{text} ({rand_wait}s)') |
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.
I suggest to take the delay as argument, rather than random which only adds to complexity here.
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.
I'll be using it for consistency when I get to demonstrating the async/await versions. It adds complexity, but it's also a relatively simple path to show the impact of asynchronous code. I'm putting a pin in it, but I'd like your opinion when I've got the section complete.
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.
Should work with fixed delays similarly for both async and sync. I hope you have read https://trio.readthedocs.io/en/stable/tutorial.html which is a particularly good introduction to async issues (even when not using Trio).
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.
@Tronic after sleeping on it, I'll revise to use the delay as an argument as you suggest. I don't think the complexity is inherently a problem with using random sleep times, but given how many people seem confused about async/await removing that from the process makes sense.
|
||
# Sync and Async in Sanic | ||
|
||
Sanic is an **asynchronous** framework - it is designed to be responsive to requests, which allows it to theoretically serve more requests, more quickly, than a synchronous framework. Other python asynchronous frameworks also share the same limitations when calling synchronous code, so the guide below will hopefully serve you if you end up in a situation using something other than Sanic in the future. |
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.
Sanic is an **asynchronous** framework - it is designed to be responsive to requests, which allows it to theoretically serve more requests, more quickly, than a synchronous framework. Other python asynchronous frameworks also share the same limitations when calling synchronous code, so the guide below will hopefully serve you if you end up in a situation using something other than Sanic in the future. | |
Sanic is an **asynchronous** framework—it is designed to be responsive to requests, which allows it to theoretically serve more requests, more quickly, than a synchronous framework. Other python asynchronous frameworks also share the same limitations when calling synchronous code, so the guide below will hopefully serve you if you end up in a situation using something other than Sanic in the future. |
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.
Sorry, the typographer in me cannot overlook the mistake of a hyphen for a dash.
Can we get this finalized soon? |
Much needed guide for explaining what happens when blocking calls are used in Sanic