-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat[next]: use context vars instead of global state in embedded iterator execution #1120
Conversation
Opening as a reminder, instead of #896 |
I can clean up the code and provide a final version of this prototype without too much effort. @tehrengruber do you also agree with using this implementation strategy to fix the problem? |
Yes, given the model itself this is much better than the global variable. |
67a3ba2
to
e24fd6c
Compare
e24fd6c
to
7499384
Compare
I've requested a formal review from @tehrengruber because apparently @havogt can't approve it since he's the creator of the PR, but I think both of you should take a look. |
|
||
|
||
def test_column_multithread(): | ||
def test_func(i: int, output: list) -> None: |
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.
Is this really a meaningful test? I have no clue how the thread scheduling works in Python, but this might very well never fail even if the column range is implemented incorrectly. If we want this to be meaningful how about a lock that ensure the column construction of the first thread happens after the context setup of a second thread? (If it's not worth the effort I would remove the test altogether to be honest.)
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.
Ok, I agree and removed the test.
assert np.array_equal(res.data, a.data + b.data) | ||
assert res.kstart == 1 | ||
|
||
_run_within_context(test_func) |
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 is fine, but is there a reason to not use a context handler for this? Sure the columns would leak scope, but doesn't really matter 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.
A context handler doesn't really work here because code running inside a context needs to be an actual function (line 36). Setting the values of the context vars before running some lines of code and then restoring their previous values does not test the context vars and it doesn't work in the general case (it will fail when running multiple threads, for example).
Changed:
column_range
andoffset_provider
global variables have been converted to context variables and fencil closures are now executed in isolated contexts with properly initialized values, to avoid using global state.