This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_cleanup() of test_builtin failed
Type: behavior Stage:
Components: Tests Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2014-02-11 16:37 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue20599_print_flush.patch serhiy.storchaka, 2014-02-12 10:36 review
issue20599_ascii_ioencoding.patch serhiy.storchaka, 2014-02-12 12:31 review
Messages (19)
msg210965 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-11 16:37
http://buildbot.python.org/all/builders/x86%20XP-4%203.x/builds/10150/steps/test/logs/stdio

======================================================================
FAIL: test_cleanup (test.test_builtin.ShutdownTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_builtin.py", line 1621, in test_cleanup
    self.assertEqual(["before", "after"], out.decode().splitlines())
AssertionError: Lists differ: ['before', 'after'] != []

First list contains 2 additional elements.
First extra element 0:
before

- ['before', 'after']
+ []
msg210972 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-11 16:51
It's probably linked to recent changes from issue #19255.
msg211078 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-12 10:36
Unfortunately I can't reproduce this failure. We should look at how often this happens on buildbots. It is possible that adding flush=True in print() will solve the issue.
msg211080 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-12 10:40
New changeset 7ecee9e0dc58 by Serhiy Storchaka in branch 'default':
Try to fix test_cleanup (issue #20599).
http://hg.python.org/cpython/rev/7ecee9e0dc58
msg211081 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-12 10:53
Failed builtbots:

http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/4072/steps/test/logs/stdio
http://buildbot.python.org/all/builders/x86%20XP-4%203.x/builds/10154/steps/test/logs/stdio
http://buildbot.python.org/all/builders/x86%20Windows%20Server%202008%20%5BSB%5D%203.x/builds/2308/steps/test/logs/stdio
msg211084 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-12 11:24
> It is possible that adding flush=True in print() will solve the issue.

I tried. It does not fix the issue.

Hint: On Windows, sys.stdout.encoding is a codec implemented in pure Python (ex: cp850). You should try to reproduce the issue on Linux using PYTHONIOENCODING=cp850.

Note: It looks like open() is no more available when C.__del__() is called.
msg211087 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-12 12:31
Ah, thank you for your hint Victor. This patch should fix the issue.
msg211091 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-12 14:04
Sorry, issue20599_ascii_ioencoding.patch doesn't fix the issue. (I also tested issue20599_ascii_ioencoding.patch + flush=True for print, it still fails sometimes.)
msg211103 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-12 17:15
What if use "-u" flag? "utf-8" or "utf_8" encoding?
msg211105 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-12 17:28
New changeset 10ea3125d7b8 by Victor Stinner in branch 'default':
Issue #20599: Force ASCII encoding for stdout in test_cleanup() of test_builtin
http://hg.python.org/cpython/rev/10ea3125d7b8
msg211106 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-12 17:31
> Sorry, issue20599_ascii_ioencoding.patch doesn't fix the issue.

Sorry again, I didn't read issue20599_ascii_ioencoding.patch carefully: it doesn't make sense to use the isolated mode and to set a Python environment variable (PYTHONIOENCODING). The purpose of the isolated mode is to ignore all Python environment variables...

I (hope I) fixed the test, but in fact, the test showed another bug: print() cannot be used during Python exit in destructor. It means for example that Python may not be able to display errors at exit.

I don't know if this issue should be closed. Maybe a new issue should be opened to address the codec issue at exit?
msg211111 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-12 19:24
Now test fails with mystical error.

http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/4074/steps/test/logs/stdio
http://buildbot.python.org/all/builders/x86%20Windows%20Server%202008%20%5BSB%5D%203.x/builds/2312/steps/test/logs/stdio

======================================================================
FAIL: test_cleanup (test.test_builtin.ShutdownTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_builtin.py", line 1628, in test_cleanup
    __cleanenv=True)
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\script_helper.py", line 69, in assert_python_ok
    return _assert_python(True, *args, **env_vars)
  File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\script_helper.py", line 55, in _assert_python
    "stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore')))
AssertionError: Process return code is 2147483651, stderr follows:
Fatal Python error: Failed to initialize Windows random API (CryptoGen)

----------------------------------------------------------------------
msg211112 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-12 19:29
May be setting PYTHONHASHSEED will silence this error. But I afraid there is a real bug in initialization on Windows.
msg211113 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-12 19:42
> I (hope I) fixed the test, but in fact, the test showed another bug: print() cannot be used during Python exit in destructor. It means for example that Python may not be able to display errors at exit.

print() can be used during Python exit in destructor if destructor called before cleaning up the builtins and sys modules and encoding module with the encoding of sys.stdout.

Cleaning up the builtins and sys modules are delayed after wiping other modules, this decreases the chance of print() failure.
msg211134 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-13 09:51
Another failure:

http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.0%203.x/builds/1724/steps/test/logs/stdio

======================================================================
FAIL: test_cleanup (test.test_builtin.ShutdownTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/home/buildbot/koobs-freebsd10/3.x.koobs-freebsd10/build/Lib/test/test_builtin.py", line 1628, in test_cleanup
    __cleanenv=True)
  File "/usr/home/buildbot/koobs-freebsd10/3.x.koobs-freebsd10/build/Lib/test/script_helper.py", line 69, in assert_python_ok
    return _assert_python(True, *args, **env_vars)
  File "/usr/home/buildbot/koobs-freebsd10/3.x.koobs-freebsd10/build/Lib/test/script_helper.py", line 55, in _assert_python
    "stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore')))
AssertionError: Process return code is 1, stderr follows:
Shared object "libpython3.4dm.so.1" not found, required by "python"
msg211135 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-13 09:54
New changeset 488ccbee6ee6 by Victor Stinner in branch 'default':
Issue #20599: Don't clear environment in test_cleanup() of test_builtin
http://hg.python.org/cpython/rev/488ccbee6ee6
msg211137 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-13 10:07
> Shared object "libpython3.4dm.so.1" not found, required by "python"

This is probably is missing LD_LIBRARY_PATH environment variable.

> Fatal Python error: Failed to initialize Windows random API (CryptoGen)

Oh, it remembers me that Windows requires some environment variables to start, otherwise it fails badly.

I modified the test to *not* start with an empty environment, it's not the purpose of the test.
msg211144 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-13 10:51
> This is probably is missing LD_LIBRARY_PATH environment variable.
>> Fatal Python error: Failed to initialize Windows random API (CryptoGen)
>Oh, it remembers me that Windows requires some environment variables to start, otherwise it fails badly.

Ok, I filled issue #20614 to track these bugs with __cleanenv=True.

Serhiy>print() can be used during Python exit in destructor if destructor called before cleaning up the builtins and sys modules and encoding module with the encoding of sys.stdout.
Serhiy>Cleaning up the builtins and sys modules are delayed after wiping other modules, this decreases the chance of print() failure.

Ah ok. I tested with a codec implemented in Python, it works well. So it is very specific to test_cleanup() which hack builtins and sys modules to keep a reference their.

I don't see anything else to do, I close the issue.
msg213814 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-17 06:30
New changeset 3d5154fa8413 by Serhiy Storchaka in branch '3.4':
Try to fix test_cleanup (issue #20599).
http://hg.python.org/cpython/rev/3d5154fa8413

New changeset c978dffb95ac by Victor Stinner in branch '3.4':
Issue #20599: Force ASCII encoding for stdout in test_cleanup() of test_builtin
http://hg.python.org/cpython/rev/c978dffb95ac

New changeset 1fb37d2d7d9d by Victor Stinner in branch '3.4':
Issue #20599: Don't clear environment in test_cleanup() of test_builtin
http://hg.python.org/cpython/rev/1fb37d2d7d9d
History
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64798
2014-03-17 06:30:56python-devsetmessages: + msg213814
2014-02-13 10:51:35vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg211144
2014-02-13 10:07:59vstinnersetmessages: + msg211137
2014-02-13 10:02:34serhiy.storchakasetmessages: - msg211136
2014-02-13 10:01:47serhiy.storchakasetmessages: + msg211136
2014-02-13 09:54:52python-devsetmessages: + msg211135
2014-02-13 09:51:11vstinnersetmessages: + msg211134
2014-02-12 19:42:19serhiy.storchakasetmessages: + msg211113
2014-02-12 19:29:37serhiy.storchakasetmessages: + msg211112
2014-02-12 19:24:30serhiy.storchakasetmessages: + msg211111
2014-02-12 17:31:43vstinnersetmessages: + msg211106
2014-02-12 17:28:58python-devsetmessages: + msg211105
2014-02-12 17:15:33serhiy.storchakasetmessages: + msg211103
2014-02-12 14:04:25vstinnersetmessages: + msg211091
2014-02-12 12:31:37serhiy.storchakasetfiles: + issue20599_ascii_ioencoding.patch

messages: + msg211087
2014-02-12 11:24:42vstinnersetmessages: + msg211084
2014-02-12 10:53:43serhiy.storchakasetmessages: + msg211081
2014-02-12 10:40:49python-devsetnosy: + python-dev
messages: + msg211080
2014-02-12 10:36:56serhiy.storchakasetfiles: + issue20599_print_flush.patch
messages: + msg211078

components: + Tests
keywords: + patch
type: behavior
2014-02-11 16:51:59vstinnersetnosy: + pitrou
messages: + msg210972
2014-02-11 16:37:29vstinnercreate