Skip to content
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

Traceback appears twice in v0.14 #70

Closed
cyril-allignol opened this issue Aug 21, 2015 · 7 comments
Closed

Traceback appears twice in v0.14 #70

cyril-allignol opened this issue Aug 21, 2015 · 7 comments

Comments

@cyril-allignol
Copy link

I use a pyconsole in a latex-beamer frame, with an expression leading to an error. For example:

\begin{frame}[fragile]
    \begin{pyconsole}
raise Exception
    \end{pyconsole}
\end{frame}

This compiles fine with pythontex3 v0.12, but produces a double backtrace with v0.14:

>>> raise Exception
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Exception
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Exception

I'm on Debian Jessie, and the package is simply loaded with \usepackage{pythontex}.

@gpoore
Copy link
Owner

gpoore commented Aug 21, 2015

I can't reproduce the problem. You might try deleting the pythontex-files-* folder to see if that helps.

Are you loading any packages besides pythontex? It's possible that there's a package conflict.

@cyril-allignol
Copy link
Author

Deleting pythontex-files-* didn't help (tried this before posting an issue). I didn't thought about a package conflict, but it turns out this is not so obvious : I tried with the following minimal example (without all the beamer package and stuff), and the output still contains two backtraces instead of one.

\documentclass[pdftex]{article}
\usepackage{pythontex}
\begin{document}
\begin{frame}[fragile]
  \begin{pyconsole}
raise Exception
  \end{pyconsole}
\end{frame}
\end{document}

@gpoore
Copy link
Owner

gpoore commented Aug 24, 2015

In the directory with the main .tex file, there will be a .pytxcode file. If you could post the contents of that, it might give me an idea of what is happening.

@cyril-allignol
Copy link
Author

The .pytxcode files for v0.12 and v0.14 are identical:

=>PYTHONTEX#pycon#default#default#0#console#####6#
raise Exception
=>PYTHONTEX:SETTINGS#
version=0.14
outputdir=pythontex-files-bim
workingdir=.
workingdirset=false
gobble=none
rerun=default
hashdependencies=default
makestderr=false
stderrfilename=full
keeptemps=none
pyfuture=default
pyconfuture=none
pygments=true
pygglobal=:GLOBAL||
fvextfile=-1
pyconbanner=none
pyconfilename=stdin
depythontex=false
pygfamily=py|python|
pygfamily=pycon|pycon|
pygfamily=sympy|python|
pygfamily=sympycon|pycon|
pygfamily=pylab|python|
pygfamily=pylabcon|pycon|

The only files that differ significantly are the .pytxpyg files. Following are the last lines of those files where we can see a duplication of the traceback:

v0.12:

.....
\begin{SaveVerbatim}[commandchars=\\\{\}]{pytx@pycon@default@default@0}
\PYGdefault{g+gp}{\PYGdefaultZgt{}\PYGdefaultZgt{}\PYGdefaultZgt{} }\PYGdefault{k}{raise} \PYGdefault{n+ne}{Exception}
\PYGdefault{g+gt}{Traceback (most recent call last):}
  File \PYGdefault{n+nb}{"\PYGdefaultZlt{}stdin\PYGdefaultZgt{}"}, line \PYGdefault{l+m}{1}, in \PYGdefault{n}{\PYGdefaultZlt{}module\PYGdefaultZgt{}}
\PYGdefault{g+gr}{Exception}
\end{SaveVerbatim}

v0.14:

.....
\begin{pytx@SaveVerbatim}[commandchars=\\\{\}]{pytx@pycon@default@default@0}
\PYGdefault{g+gp}{\PYGdefaultZgt{}\PYGdefaultZgt{}\PYGdefaultZgt{} }\PYGdefault{k}{raise} \PYGdefault{n+ne}{Exception}
\PYGdefault{g+gt}{Traceback (most recent call last):}
  File \PYGdefault{n+nb}{\PYGdefaultZdq{}\PYGdefaultZlt{}stdin\PYGdefaultZgt{}\PYGdefaultZdq{}}, line \PYGdefault{l+m}{1}, in \PYGdefault{n}{\PYGdefaultZlt{}module\PYGdefaultZgt{}}
\PYGdefault{g+gr}{Exception}
\PYGdefault{g+gt}{Traceback (most recent call last):}
  File \PYGdefault{n+nb}{\PYGdefaultZdq{}\PYGdefaultZlt{}stdin\PYGdefaultZgt{}\PYGdefaultZdq{}}, line \PYGdefault{l+m}{1}, in \PYGdefault{n}{\PYGdefaultZlt{}module\PYGdefaultZgt{}}
\PYGdefault{g+gr}{Exception}
\end{pytx@SaveVerbatim}

@gpoore
Copy link
Owner

gpoore commented Aug 25, 2015

Can you give me your complete Python version, so I can check that on my system?

I think I'm getting closer on diagnosing the issue. Under Ubuntu 14.04, Python 2.7.6 gives correct output but Python 3.4.0 is completely omitting all traceback information. The traceback is ending up in the terminal instead. Under Windows, everything works fine for Python 3.4.1. My guess is that Python 3 treats the emulated console stdout and stderr differently on some systems, so that it is being doubled (your case) or ending up in the wrong place (my Ubuntu case). I will need to look into how Python's code module is different in Python 3. It's also possible that there's a system-dependent bug in PythonTeX, though I don't remember changing anything major console-related between 0.12 and 0.14.

@cyril-allignol
Copy link
Author

I'm running Python 3.4.2 on a Debian Jessie.

The samples I provided for v0.12 (the correct ones) use Python 3.2.3 on a Debian Wheezy, so there might have been changes between those two versions.
Also I can confirm that on an Ubuntu 15.04 with Python 3.4.?, there is no traceback at all.

@gpoore
Copy link
Owner

gpoore commented Aug 26, 2015

I believe I've found the issue and a solution. Apparently Ubuntu's apport system automatically hooks into Python's exception handling, by creating a custom sys.excepthook. Meanwhile, Python 3's version of the code module checks for a custom sys.excepthook, and uses it if it's available (Python 2 ignored custom sys.excepthook). So this is system-dependent, and the solution is to use sys.__excepthook__. Presumably, Debian is doing something similar, but with a different sys.excepthook that causes different problems. I just committed a fix that works under Ubuntu and should fix Debian as well.

(Reference for finding the solution.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants