-
Notifications
You must be signed in to change notification settings - Fork 325
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
Python: Pass the env parameter into handlers #1610
Conversation
Before this PR we instantiate the Python interpreter from scratch on every request. This is slow and uses up a lot of memory. This switches to sharing an interpreter across requests. This makes per-request non-coldstart execution time and memory usage much lower.
This adds a relaxed_call function taken from pyodide/pyodide#4392 and uses it to pass the env argument to the fetch/test handlers
async fetch(request, env) { | ||
const mainModule = await getMainModule(); | ||
return await mainModule.fetch(request); | ||
async fetch(ctx, env) { |
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.
Not sure we should rename request
to ctx
here. With fetch(...)
handlers, the third argument is the ExecutionContext
that, by convention, we've typically named ctx
. Would be good to avoid confusion 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.
What about for test
? Should the first argument always be called request
? And presumably if fetch
takes a third argument I should pass that along too?
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.
No, for test
it should be ctx
. I'm not a big fan of the difference but that first argument to fetch
is a Request
object so the name should match.
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.
Actually, test
's arguments are test(controller, env, ctx)
. ctx
is still the third argument. controller
is equivalent to request
.
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.
Awesome!
This allows Python workers to access secrets and such.
This adds a relaxed_call function and uses it to pass the env argument to the fetch/test handlers.
The relaxed_call implementation is from here:
pyodide/pyodide#4392