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
atexit module not safe in Python 3.0 with multiple interpreters #48450
Comments
In Python 3.0 the atexit module was translated from Python code to C code. Prior to Python 3.0, because it was implemented at C code level, the list of The end result is that if a sub interpreter registers an atexit callback, that Various problems could ensue from this depending on whether or not the sub Still need to validate the above, but from visual inspection looks to be a For mod_wsgi case, since it is explicitly triggering atexit callbacks for sub Even if mod_wsgi weren't doing this, still a problem that Py_Finalize() calling For mod_wsgi, will probably end up installing own 'atexit' module variant in |
Ouch! We totally forgot about sub interpreters during the In my opinion it's a big bug for systems like mod_python and mod_wsgi. Do you have a suggestion how the problem should be solved? I'd store the By the way PEP-3121 ... does the new module initialization code play |
I wouldn't be concerned about mod_python as likelihood that it will be ported is As to mod_wsgi, I can work around it in the short term by installing an 'atexit' As to a solution, yes, using PyInterpreterState would seem the most logical place, Prior to Python 3.0, any callbacks registered with atexit module in sub interpreters So, although one may register sub interpreter atexit callbacks against PyInterpreterState, what would be done with them. A decision would need to be made In the short term, ie., for Python 3.0.0, the simplest thing to do may be to have The only place this would probably cause a problem would be for mod_wsgi where it By having atexit module ignore stuff for sub interpreters, at least for now avoid And no I haven't looked at how PEP-3121 has changed things in Python 3.0. Up till |
I'm adding Martin to the nosy list as well. He is the author of PEP-3121 |
It would certainly be possible to produce per-interpreter callback lists Reviewing the code, I have two unrelated remarks:
According to the documentation of the atexit module, it seems clear that |
I'm trying to come up with a patch. It's a little bit trickier than I In order to use PEP-3121 we have to add a mechanism to pass the module |
Christian Heimes wrote:
(I actually meant PyModule_GetState). You can use PyState_FindModule to quickly lookup a module. |
Ah, thanks. I'll try PyState_FindModule(). |
Can you review the patch, Martin? I've moved the three state variables |
Martin, can you please review and comment on my patch? Graham, does the patch solve your problem? |
By visual inspection the intent looks correct, but can't actually test it With bpo-3723 and bpo-4213 now also having patches, will need to sit down and |
This patch looks fine. |
Fixed in r67054 |
I know this issue is closed, but for this patch, the code: + modstate = get_atexitmodule_state(module); was added. Is there any condition under which modstate could be NULL. Haven't touched Python 3.0 support in mod_wsgi for a long time and when |
2009/7/19 Graham Dumpleton <report@bugs.python.org>:
The module is probably being deallocated before the callbacks are being called.
|
This new problem I am seeing looks like it may be linked to where the PyImport_ImportModule("atexit");
Py_Finalize(); At a guess, this is because: module = PyState_FindModule(&atexitmodule);
if (module == NULL)
return; still returns a module for case where imported in a sub interpreter but modstate = GET_ATEXIT_STATE(module);
returns NULL for modstate for the main interpreter as PyInit_atexit() The fix would appear to be to check modstate for being NULL and return. module = PyState_FindModule(&atexitmodule);
if (module == NULL)
return;
modstate = GET_ATEXIT_STATE(module);
Does that make sense to anyone? If it does and I am correct, I'll create |
Have created bpo-6531 for my new issue related to this patch. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: