[issue19421] FileIO destructor imports indirectly the io module at exit

2014-10-10 Thread Martin Panter
Martin Panter added the comment: For the record, the python-dev thread about blocking imports is at . It sounded like the conclusion was that there shouldn’t be a problem importing a module at finalization. I am investigat

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-31 Thread STINNER Victor
STINNER Victor added the comment: I misunderstood the gdb traceback. Display a warning does not reload the io module: in fact, the io module was unloaded and PyImport_ImportModuleLevelObject() already raises an ImportError in this case: ImportError("import of 'io' halted; None in sys.modules")

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-29 Thread STINNER Victor
STINNER Victor added the comment: Trying to reimport the io module is not the only issue of emitting warnings during Python shutdown. I just found a new issue after fixing an unrelated bug in the warnings module (issue #19424): issue #19442 "Python crashes when a warning is emitted during shut

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis : -- nosy: +Arfrever ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread STINNER Victor
STINNER Victor added the comment: +PyErr_SetString(PyExc_ImportError, "__import__ blocked Python finalization"); Oops, I forgot "during" word before Python finalization. "import" is maybe less surprising than "__import__". -- ___ Python

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread STINNER Victor
STINNER Victor added the comment: "Again, I don't think this is a good patch. If you want to disable module imports during shutdown, it should be done inside the import machinery, not duplicated at every call site." Ah sorry, I misunderstood your previous comment. I agree that traceback_fina

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread Roundup Robot
Roundup Robot added the comment: New changeset 2d802765d31f by Victor Stinner in branch 'default': Issue #19421: add an unit test for warnings.warn() during finalization http://hg.python.org/cpython/rev/2d802765d31f -- ___ Python tracker

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread Antoine Pitrou
Antoine Pitrou added the comment: Again, I don't think this is a good patch. If you want to disable module imports during shutdown, it should be done inside the import machinery, not duplicated at every call site. (but I don't necessarily agree that it's a good idea, either) -- __

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread STINNER Victor
STINNER Victor added the comment: > New changeset 1bbedfb20932 by Victor Stinner in branch 'default': > Issue #19421: fix a check in warnings.warn() to be able to use it during > Python > http://hg.python.org/cpython/rev/1bbedfb20932 Without this fix, the following script crashs with an asserti

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread STINNER Victor
STINNER Victor added the comment: Here is a patch to not import again the io module in _Py_DisplaySourceLine() if the module was unloaded. A simpler patch is to just return (don't check sys.modules) if _Py_Finalizing is set. Note: I also created issue #19424 to avoid conversion from/to UTF-8.

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread Roundup Robot
Roundup Robot added the comment: New changeset 1bbedfb20932 by Victor Stinner in branch 'default': Issue #19421: fix a check in warnings.warn() to be able to use it during Python http://hg.python.org/cpython/rev/1bbedfb20932 -- nosy: +python-dev ___ P

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread Antoine Pitrou
Antoine Pitrou added the comment: Ok, then I don't think it's really a bug. We might want to define import rules at shutdown but "fixing" this particular case doesn't sound important. -- ___ Python tracker ___

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread STINNER Victor
STINNER Victor added the comment: > Can you explain what the actual cause of the crash is? I modified locally my Python source code (I worked on a patch for PyFrame_LocalsToFast(), issue #18408), the crash was a bug in my code, it's unrelated to the issue. I opened an issue because I'm surpri

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread Antoine Pitrou
Antoine Pitrou added the comment: Can you explain what the actual cause of the crash is? Surely failing to import the "io" module shouldn't produce a fatal error. -- ___ Python tracker _

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread STINNER Victor
STINNER Victor added the comment: "show_warning() and/or _Py_DisplaySourceLine() should not try to display the Python line while Python is exiting. There is for example the flag _Py_Finalizing." Or PyImport_Import() should fail with an ImportError("block importing 'io' when python is exiting"

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread STINNER Victor
STINNER Victor added the comment: By the way, the filename of the warning is not really useful. Example script test.py: - f = open(__file__) - At exit, Python displays: - sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='t

[issue19421] FileIO destructor imports indirectly the io module at exit

2013-10-28 Thread STINNER Victor
New submission from STINNER Victor: Since Python 3.3, when an unclosed file is destroyed, a warning is emitted. Good. The problem is when the warning is emitted after the io has been unloaded: in this case, the warning will try to reload the io module to display the Python line where the warn