-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-133485: Use _interpreters.call() in InterpreterPoolExecutor #133957
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
base: main
Are you sure you want to change the base?
gh-133485: Use _interpreters.call() in InterpreterPoolExecutor #133957
Conversation
5340a57
to
62d7c2c
Compare
b3c2477
to
7697c11
Compare
# InterpreterPoolInitializerTest.test_initializer fails | ||
# if we don't have a LOAD_GLOBAL. (It could be any global.) | ||
# We will address this separately. | ||
INITIALIZER_STATUS |
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.
@markshannon, any ideas on why this is happening? It smells like a ceval bug, but it certainly could be something I've done wrong.
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.
ping @markshannon
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.
There seem to be related changes in inspect.getclosurevars()
since 83ba8c2:
before:
ClosureVars(nonlocals={},
globals={'INITIALIZER_STATUS': 'uninitialized'},
builtins={}, unbound=set())
after:
ClosureVars(nonlocals={},
globals={},
builtins={}, unbound=set())
init()
on main (without L26):
3 RESUME 0
5 LOAD_FAST_BORROW 0 (x)
STORE_GLOBAL 0 (INITIALIZER_STATUS)
LOAD_CONST 0 (None)
RETURN_VALUE
- 3.3.5 (2014):
5 0 LOAD_FAST 0 (x)
3 STORE_GLOBAL 0 (INITIALIZER_STATUS)
6 LOAD_CONST 0 (None)
9 RETURN_VALUE
5ea2bb2
to
14a8eb9
Compare
14a8eb9
to
ccc135c
Compare
🤖 New build scheduled with the buildbot fleet by @ericsnowcurrently for commit ccc135c 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133957%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
The |
Is the following usage invalid? INITIALIZER_STATUS = 'uninitialized'
def init(x):
global INITIALIZER_STATUS
INITIALIZER_STATUS = x
INITIALIZER_STATUS # for now
def get_init_status():
return INITIALIZER_STATUS
if __name__ == "__main__":
from concurrent.futures import InterpreterPoolExecutor
exe = InterpreterPoolExecutor(initializer=init, initargs=('initialized',))
fut = exe.submit(get_init_status)
assert fut.result() == 'initialized' # fails
exe.shutdown(wait=True)
assert INITIALIZER_STATUS == 'uninitialized' |
Line 601 in ec12559
I guess the failure case in my previous comment can be resolved if the |
That example should definitely work. You're probably right about the fix. |
I've committed a solution that fixes the failure. The quirky thing, I realized, is that the loaded functions use the cached NS for |
This comment was marked as resolved.
This comment was marked as resolved.
I think we're okay on this. The unpickled function isn't actually bound anywhere in the subinterpreter. Instead, it is pulled from the cached namespace, called, and then discarded (decref'ed). At worst, the function could treat its own |
A concern is that the shared items can conflict with the InterpreterPoolExecutor(..., shared={'init': None}) If putting that aside, could |
task = (fn, args, kwargs) | ||
data = pickle.dumps(task) |
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 like pickle
and contextlib
are now unused in this file. Importing pickle
might be unnecessary when running only stateless functions?
Good point. The
That is essentially the same as exec'ing the original One alternative is to add a new module, e.g. |
@neonene, thanks for all the super helpful comments and feedback. You've had a real impact on the outcome here! |
Most importantly, this resolves the issues with functions and types defined in
__main__
.It also expands the number of supported objects.
(This is based on gh-133484, thus only the last commit.)