<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi everybody,<br>
    <br>
    is there something like a hook that a Python module could register
    to in order to 'trace' the entering and leaving of arbitrary try
    blocks?<br>
    <br>
    <br>
    What is this good for?<br>
    <br>
    I am the maintainer of <a class="moz-txt-link-freetext" href="https://pypi.python.org/pypi/xfork">https://pypi.python.org/pypi/xfork</a> . A
    package for converting a classic sequential program to a parallel
    one.<br>
    In order to make sure exception handling basically works the same
    way as in the sequential implementation, it would be great if I
    could hook into try blocks.<br>
    <br>
    <br>
    Consider this:<br>
    <br>
    <font face="monospace">try:<br>
          return 25+fork(b)<br>
      except:<br>
          return 11<br>
      finally:<br>
          print('finished')</font><br>
    <br>
    <br>
    <font face="monospace">25+fork(b) <font face="sans-serif">is a
        ResultProxy</font></font>. That kind of object is basically
    wraps up operators and evaluate them lazily.<br>
    <br>
    In order to preserve sequential/classic exception handling, I would
    like to evaluate all open/not-already-evaluated result proxies as
    soon as I enter or leave a try: block.<br>
    <br>
    <br>
    Why when leaving try:?<br>
    Result proxies might raise exceptions once they evaluate. So, result
    proxies evaluated outside of their origin try: block, might get
    caught somewhere else by the wrong exception handler.<br>
    <br>
    Why when entering try:?<br>
    Result proxies might raise exceptions once they evaluate. So, result
    proxies from before the try: might raise exceptions which in turn
    might be caught inside the try: by the wrong exception handler.<br>
    <br>
    Best,<br>
    Sven<br>
    <br>
    <br>
    PS: I already looked into the source of CPython and discovered these
    places:<br>
    <br>
<a class="moz-txt-link-freetext" href="https://github.com/python/cpython/blob/d95bb1adefc7/Python/symtable.c#L947symtable_enter_block">https://github.com/python/cpython/blob/d95bb1adefc7/Python/symtable.c#L947symtable_enter_block</a><br>
    <a class="moz-txt-link-freetext" href="https://github.com/python/cpython/blob/d95bb1adefc7/Python/symtable.c#L931">https://github.com/python/cpython/blob/d95bb1adefc7/Python/symtable.c#L931</a>
    symtable_exit_block<br>
    <br>
    Unfortunately, I cannot find anything specific to exception handling
    in the source.<br>
  </body>
</html>