[pypy-dev] Bringing Cython and PyPy closer together

Amaury Forgeot d'Arc amauryfa at gmail.com
Sat Feb 18 15:41:42 CET 2012

2012/2/18 Stefan Behnel <stefan_ml at behnel.de>

> Here's an example.
> Python code:
>  def print_excinfo():
>      print(sys.exc_info())
> Cython code:
>  from stuff import print_excinfo
>  try:
>      raise TypeError
>  except TypeError:
>      print_excinfo()
> With the code removed, Cython will not store the TypeError in
> sys.exc_info(), so the Python code cannot see it. This may seem like an
> unimportant use case (who uses sys.exc_info() anyway, right?), but this
> becomes very visible when the code that uses sys.exc_info() is not user
> code but CPython itself, e.g. when raising another exception or when
> inspecting frames. Things grow really bad here, especially in Python 3.

I think I understand now, thanks for your example.
Things are a bit simpler in PyPy because these exceptions are
stored in the frame that is currently handling it. At least better than
which stores it in one place, and has to somehow save the state of the
previous frames.
Did you consider adding such a function to CPython?

For the record, pypy could implement it as:
space.getexecutioncontext().gettopframe_nohidden().last_exception =
i.e. the thing returned by sys.exc_info().

Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20120218/02100da4/attachment-0001.html>

More information about the pypy-dev mailing list