-
Notifications
You must be signed in to change notification settings - Fork 85
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
More comprehensive recursion guard. #460
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9ebceb8
More comprehensive recursion guard.
jerith 09c043b
Use rstrs instead of symbols for recursion identifiers.
jerith a2212c9
Merge branch 'master' into jerith/better-recursion-guard
jerith 7baabb3
Switch back to previous Thread.recursion_guard() API.
jerith 2ad4cf2
Switch API on Thread.recursion_guard_outer() as well.
jerith a8bfa13
Merge branch 'master' into jerith/better-recursion-guard
jerith 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
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,26 @@ | ||
class Thread | ||
def recursion_guard_outer(identifier, obj, &block) | ||
# We want to throw something less likely to be caught accidentally outside | ||
# our own code than the recursion identifier. Ideally this should be an | ||
# object that is unique to this particular recursion guard. Since doing | ||
# that properly requires pushing extra state all the way up into | ||
# ExecutionContext, we do this instead. | ||
throw_symbol = "__recursion_guard_#{identifier}".to_sym | ||
|
||
if self.in_recursion_guard?(identifier) | ||
self.recursion_guard(identifier, obj) do | ||
yield | ||
return false | ||
end | ||
throw(throw_symbol) | ||
else | ||
self.recursion_guard(identifier, obj) do | ||
catch(throw_symbol) do | ||
yield | ||
return false | ||
end | ||
return true | ||
end | ||
end | ||
end | ||
end | ||
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
class TestExecutionContext(object): | ||
def test_recursion_guard(self, space): | ||
f = "my_func" | ||
x = object() | ||
y = object() | ||
with space.getexecutioncontext().recursion_guard(x) as in_recursion: | ||
with space.getexecutioncontext().recursion_guard(f, x) as in_recursion: | ||
assert not in_recursion | ||
with space.getexecutioncontext().recursion_guard(y) as ir2: | ||
with space.getexecutioncontext().recursion_guard(f, y) as ir2: | ||
assert not ir2 | ||
with space.getexecutioncontext().recursion_guard(x) as ir3: | ||
with space.getexecutioncontext().recursion_guard(f, x) as ir3: | ||
assert ir3 | ||
with space.getexecutioncontext().recursion_guard(x) as ir3: | ||
with space.getexecutioncontext().recursion_guard(f, x) as ir3: | ||
assert ir3 |
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.
This isn't used yet, right?
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, but I need it for Array#hash in #456.
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 think this is becoming my official theme song, but let's split this up :D, so this just has the
identifier
for recursion guards.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 it have
Thread.in_recursion_guard?
as well? That's only used by the outer guard.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.
Nope, just what's needed. :)
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 have been more precise, just what's needed for the
recursion_guard()
changes.