Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

new preserve context implementation#4666

Merged
davidism merged 1 commit intomainfrom
debug-context
Jul 1, 2022
Merged

new preserve context implementation#4666
davidism merged 1 commit intomainfrom
debug-context

Conversation

@davidism
Copy link
Member

@davidismdavidism commentedJul 1, 2022
edited
Loading

Uses the new mechanism introduced bypallets/werkzeug#2439 to preserve the app and request context. If thewerkzeug.debug.preserve_context key is in the environ, it is a callable. It is called to record context managers that should be entered again after the request ends. Rather than keeping the contexts on the stack for longer, this allows preserving the contexts independently of the context-local stack and subsequent requests.

Becauserequest,g, etc. are context-local, they would never be available in the debugger when using the default threaded server. Now they will point to the correct data in the debugger. The same mechanism is used by the test client.

The contexts are now always popped at the end of the request, even if they are preserved. This means teardown functions will run to clean up resources. The previous implementation would pop the preserved context from the stack on the next, but that would never happen when using the threaded server because each request would be in a new thread with its own stack. I have a feeling this was causing issues especially with Flask-SQLAlchemy, where connections would never be released for requests caught by the debugger.

The contexts are restored after the request finishes in the test client, or when code is executed in the debugger. This means that signals will run each time, and teardown functions will run each time.

Only the contexts directly preserved bywerkzeug.debug.preserve_context are popped. This reverts#3157, which caused every instance of the same context to be popped. This means that the context preserved withstream_with_context will not be popped when awith client block ends, it will only be popped onceresponse.data is read (orresponse.close() is called).

closes#2836

@davidismdavidism added this to the2.2.0 milestoneJul 1, 2022
@davidismdavidism merged commit6916697 intomainJul 1, 2022
@davidismdavidism deleted the debug-context branchJuly 1, 2022 19:35
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJul 16, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

2.2.0

Development

Successfully merging this pull request may close these issues.

request points to wrong object in debugger when threading is enabled

1 participant

@davidism

Comments


[8]ページ先頭

©2009-2026 Movatter.jp