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
Add Litestar example to documentation #284
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks!
docs/guide.md
Outdated
profiler.start() | ||
|
||
async def send_wrapper(message: Message) -> None: | ||
if message["type"] == "http.response.body": | ||
message["body"] = profiler.output_html().encode() | ||
|
||
elif message["type"] == "http.response.start": | ||
profiler.stop() | ||
message["headers"] = [ | ||
(b"content-type", b"text/html; charset=utf-8"), | ||
(b"content-length", str(len(profiler.output_html())).encode()), | ||
] | ||
|
||
await send(message) | ||
|
||
await self.app(scope, receive, send_wrapper) |
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.
It seems maybe a bit wasteful to render the session twice. Does this work?
profiler.start() | |
async def send_wrapper(message: Message) -> None: | |
if message["type"] == "http.response.body": | |
message["body"] = profiler.output_html().encode() | |
elif message["type"] == "http.response.start": | |
profiler.stop() | |
message["headers"] = [ | |
(b"content-type", b"text/html; charset=utf-8"), | |
(b"content-length", str(len(profiler.output_html())).encode()), | |
] | |
await send(message) | |
await self.app(scope, receive, send_wrapper) | |
profiler.start() | |
profile_html: str | None = None | |
async def send_wrapper(message: Message) -> None: | |
if message["type"] == "http.response.start": | |
profiler.stop() | |
nonlocal profile_html | |
profile_html = profiler.output_html() | |
message["headers"] = [ | |
(b"content-type", b"text/html; charset=utf-8"), | |
(b"content-length", str(len(profile_html)).encode()), | |
] | |
elif message["type"] == "http.response.body": | |
message["body"] = profile_html.encode() | |
await send(message) | |
await self.app(scope, receive, send_wrapper) |
Also I flipped the order around in the if statement to match the order it (presumably) executes in.
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.
of course!
@joerick fixed but seems that sphinx need version bump or smth |
Describes the process of integrating pyinstrument into Litestar middleware