Closed samuelchodur closed 2 years ago
working as expected here on linux / python 3.9.5 / ipython 8.30 and osx python 3.9.9 / ipython 7.22
Can't reproduce. Maybe try updating IPython. Please reopen if needed.
Can't reproduce. Maybe try updating IPython. Please reopen if needed.
I am using IPython version 8.5.0. Are you trying to reproduce the problem on Windows? I don't have issues on Linux.
Oh this is Windows.. whelp, can't say anything about Windows really.
Oh this is Windows.. whelp, can't say anything about Windows really.
could this get set back to bug-unconfirmed then until someone else comes along with same issue as I am having?
@samuelchodur what kind of prompt is that then exactly? Ipython started in an Anaconda shell or however that is called? If so what Anaconda version? Is that problem exclusive to doing "import obspy" as first import? What happens if you import some other package first (e.g. numpy)?
@ThomasLecocq ever had any issues like that?
I just tried this on an windows laptop and I can reproduce with python 3.10.7, Ipython 8.5.0, obspy 1.3.0. This is when calling ipython from the dos terminal. When running from the IDLE shell, or via the non-ipython terminal, it works normally.
In ipython I even get the same "1;31m" errors just by attempting to import a non-existing obspy module, e.g. from obspy.geodetics.base import blahblah
so it seems like the whole environment is being contaminated just by browsing. No idea what that's about or what 1;31m
refers to.
@filefolder can you confirm this exclusively happens for obspy import? No other modules like numpy etc?
No idea what that's about or what
1;31m
refers to.
That's fragments of ANSI color codes, although I only know about Linux and have no idea if Windows uses these
https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
It looks like the escape character at the start of coloring commands gets garbled, that's why I'm puzzled how obspy would be responsible, since the coloring commands should be done by ipython.
I confirm this happens on window's CMD console, not on my Cmder console...
so far tried to import numpy, scipy, requets, pkg_resources, matplotlib : no issue
yeah I went down the line importing things related-to, seemed to be fine. weird one.
I'm testing all imports sequentially, will report later :-)
and it seems that the first to break the ansi colors in the windows console when running
ipython -c import obspy.core.util.misc;print(tom)
The reasoning seems to be linked to this old stuff https://github.com/ipython/ipython/issues/17, i.e. messing around with stdout!
So, removing some stdout rewrites from the file: https://github.com/obspy/obspy/blob/f6426d4fcd75932872ea2a56056d9e44ccec2e74/obspy/core/util/misc.py#L337-L339
makes the output look normally coloured !!
So, question is: do we really need def _py36_windowsconsoleio_workaround()
?
So, question is: do we really need
def _py36_windowsconsoleio_workaround()
?
What is that even and no idea. Probably just getting rid of it is fine. Can somebody on Windows check what happens without it on Python 3.7 (minimum for upcoming 1.3.1), 3.8 (minimum for upcoming 1.4.0), 3.9, 3.10?
In any case we don't support 3.6 no more
commenting the _py36_windows... call on line 342 in core/util/misc.py fixes the ipython bug for python 3.7.9 and python 3.10.7. unlikely I will get around to testing 3.8 or 3.9 but seems safe to interpolate.
kudos to thomas!
@filefolder @ThomasLecocq I just noticed.. this hack was for the SuppressOutput
context manager, that is apparently what crashed. Can you try something like the following on Py 3.7 and maybe 3.10 with that hack commented out?
import os
import sys
from obspy.core.util.misc import SuppressOutput
with SuppressOutput():
print('Hello')
print('Hello', file=sys.stdout)
print('Hello', file=sys.stderr)
os.system('echo "mystdout"')
os.system('echo "mystderr" >&2')
that crashes for me in 3.10 with commenting out _py36_windowsconsoleio_workaround()
and works without commenting
that crashes for me in 3.10 with commenting out
_py36_windowsconsoleio_workaround()
and works without commenting
Hmm.. so looks like the hack is still needed? Hrrrrmmmmm
@filefolder @ThomasLecocq so I saw that workaround actually is copied from pytest, and it looks to me as if its still in there: https://github.com/pytest-dev/pytest/blob/1c31a7e6598ff0290012f56c4ee6ce48a31486d9/src/_pytest/capture.py#L128
So maybe it could be an option to do this workaround hack in that SuppressOutput
context manager during __enter__
and then revert it during __exit__
? That manager would have to be rewritten though, it's using this other yield
setup right now. Would you like to look into that? I could, but then I couldnt try it out, lacking Windows, so that'd be kinda pointless.
I'm always happy to test things out but it's via a field notebook we keep in our store room so it's not something I tend to use indoors. Windows in general is a bit of a mystery to me and I admit my desire to learn more about it is nil.
@ThomasLecocq can you (or some other Win person) maybe try out the branch in #3171 on py 3.7 (or a later Python, I guess) and see if colored output works before and after running this in IPython
:
import os
import sys
from obspy.core.util.misc import SuppressOutput
with SuppressOutput():
print('Hello')
print('Hello', file=sys.stdout)
print('Hello', file=sys.stderr)
os.system('echo "mystdout"')
os.system('echo "mystderr" >&2')
This is my last shot at this before bumping this to a later release, doesn't really make sense for me to work on this on a Linux machine.
on it
sadly not OK on the default CMD of windows or the Anaconda Prompt (maybe it's an old version), but OK on cmder ... Anyway, I think your PR makes sense as the "SuppressOutput" shouldn't be loaded by default , but only when needed, no ?
Thanks for checking @ThomasLecocq.. hmm, so if I understand correctly that hacky workaround was added because Python was actually crashing on Py 3.6 at some point without it.
The new try in #3171 seems to not make anything crash and it at least makes it so IPython looks fine until SuppressOutput
is first used, which shouldn't happen in user land at all pretty much, it's only used in some of our tests as far as I can see.
So, I'd be inclined to merge #3171
should be fixed by #3171
Avoid duplicates
Bug Summary
After importing obspy, my IPython terminal does not print colored output. Tried this in several terminals on Windows (Git Bash and Anaconda Powershell Prompt). I can import other packages and continue to see colored output. Tested with 1.2.2 as well and had same problem.
Code to Reproduce
Error Traceback
No response
ObsPy Version?
1.3.0, 1.2.2
Operating System?
Windows
Python Version?
3.10
Installation Method?
conda