nghung270192 / colorama

Automatically exported from code.google.com/p/colorama
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Doesn't check for closed file when resetting in atexit handler; causes exception on exit in py.test #50

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Write some test code that imports colorama and fails
2. Run py.test on it

What is the expected output? What do you see instead?
On exit, one gets:
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/initialise.py", line 18, in reset_all
    AnsiToWin32(orig_stdout).reset_all()
  File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/ansitowin32.py", line 126, in reset_all
    elif is_a_tty(self.wrapped):
  File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/ansitowin32.py", line 15, in is_a_tty
    return hasattr(stream, 'isatty') and stream.isatty()
ValueError: I/O operation on closed file

Original issue reported on code.google.com by msabr...@gmail.com on 24 Jan 2014 at 8:31

GoogleCodeExporter commented 9 years ago
Here's a patch that fixes the issue.

Original comment by msabr...@gmail.com on 24 Jan 2014 at 8:34

Attachments:

GoogleCodeExporter commented 9 years ago
Another way to reproduce the problem:

$ python -c 'import colorama, sys; colorama.init(); sys.stdout.close()' Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(_targs, _kargs) File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/initialise.py", line 18, in reset_all AnsiToWin32(orig_stdout).reset_all() File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/ansitowin32.py", line 126, in reset_all elif is_a_tty(self.wrapped): File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/ansitowin32.py", line 15, in is_a_tty return hasattr(stream, 'isatty') and stream.isatty() ValueError: I/O operation on closed file Error in sys.exitfunc: Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(_targs, _kargs) File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/initialise.py", line 18, in reset_all AnsiToWin32(orig_stdout).reset_all() File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/ansitowin32.py", line 126, in reset_all elif is_a_tty(self.wrapped): File "/Users/marca/dev/surveymonkey/profilesvc/src/profilesvc/py26.venv/lib/python2.6/site-packages/colorama/ansitowin32.py", line 15, in is_a_tty return hasattr(stream, 'isatty') and stream.isatty() ValueError: I/O operation on closed file


The attached patch makes this go away.

Original comment by msabr...@gmail.com on 24 Jan 2014 at 8:37

GoogleCodeExporter commented 9 years ago
Acknowledged. Massive thanks for the patch.

I hope to get a bunch of recently submitted patches merged and push out a new 
release 'real soon now'.

Original comment by tart...@gmail.com on 24 Jan 2014 at 9:42

GoogleCodeExporter commented 9 years ago
Cool, let me know if you want any other changes.

Original comment by msabr...@gmail.com on 29 Jan 2014 at 12:03

GoogleCodeExporter commented 9 years ago
This is just a temporary fix, but I put a clone of this repository in GitHub 
and fixed the issue with the patch above.

My cloned repository: https://github.com/kimmobrunfeldt/colorama
I added temporary fix to my requirements.txt:
git+https://github.com/kimmobrunfeldt/colorama.git

Original comment by KimmoBru...@gmail.com on 25 Mar 2014 at 8:08

GoogleCodeExporter commented 9 years ago
I also posted my patch at my fork:

https://github.com/msabramo/colorama/pull/1
https://github.com/msabramo/colorama/tree/msabramo/issue_50
https://github.com/msabramo/colorama/commit/4a514a6fe33c4d8eb12a6737f5f8f7019833
712f

Original comment by msabr...@gmail.com on 26 Mar 2014 at 5:12

GoogleCodeExporter commented 9 years ago
Many thanks for your help Marc, this is fixed in 0.3.1, which will be pushed to 
PyPI tonight.

Original comment by tart...@gmail.com on 19 Apr 2014 at 10:11

GoogleCodeExporter commented 9 years ago
I can reproduce this even with colorama-0.3.1 on Windows 7:

$ python -c 'import colorama, sys; colorama.init(); sys.stdout.close()'
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "c:\Python26\lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "c:\Python26\lib\site-packages\colorama-0.3.1-py2.6.egg\colorama\initialise.py", line 18, in reset_all
    AnsiToWin32(orig_stdout).reset_all()
  File "c:\Python26\lib\site-packages\colorama-0.3.1-py2.6.egg\colorama\ansitowin32.py", line 65, in __init__
    convert = on_windows and is_a_tty(wrapped)
  File "c:\Python26\lib\site-packages\colorama-0.3.1-py2.6.egg\colorama\ansitowin32.py", line 16, in is_a_tty
    return hasattr(stream, 'isatty') and stream.isatty()
ValueError: I/O operation on closed file
Error in sys.exitfunc:
Traceback (most recent call last):
  File "c:\Python26\lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "c:\Python26\lib\site-packages\colorama-0.3.1-py2.6.egg\colorama\initialise.py", line 18, in reset_all
    AnsiToWin32(orig_stdout).reset_all()
  File "c:\Python26\lib\site-packages\colorama-0.3.1-py2.6.egg\colorama\ansitowin32.py", line 65, in __init__
    convert = on_windows and is_a_tty(wrapped)
  File "c:\Python26\lib\site-packages\colorama-0.3.1-py2.6.egg\colorama\ansitowin32.py", line 16, in is_a_tty
    return hasattr(stream, 'isatty') and stream.isatty()
ValueError: I/O operation on closed file

Original comment by wein...@gmail.com on 25 Aug 2014 at 12:40

GoogleCodeExporter commented 9 years ago
Created a pull request that fixes this issue: 
https://github.com/tartley/colorama/pull/17

Original comment by wein...@gmail.com on 28 Aug 2014 at 5:41

GoogleCodeExporter commented 9 years ago
Fixed by submission from github user weinimo
https://github.com/tartley/colorama/pull/17

Original comment by tart...@gmail.com on 3 Sep 2014 at 8:04