When looking at traceback of caught exception, fourth arg missing in

10 views
Skip to first unread message

walt3k

unread,
Mar 17, 2022, 3:15:08 AM3/17/22
to cython-users
In both a python .py and cython .pyx file, I have the following assert in a function wrapped by a decorator:

assert(1==2)

The decorator has a try/except statement around the calling of the above function(s)

            except Exception as e:
                e_type, e_object, e_traceback = sys.exc_info()
                traceback_info = traceback.extract_tb(e_traceback)
                print(list(traceback_info[-1]))

With python I see 4 fields filled out when the print happens
['/u/walt3k/work/cocotb/new_controls/Calc1Cocotb/pure_cocotb.py', 46, 'test_alu_add', 'assert(1==2)']

With cython I see only 3 fields - the last one is blank
['test_calc1.pyx', 56, 'test_wait_for_execute_loop_via_event', '']

I am running cython version 3.0a1 and saw the same behavior with older versions.

For my application, I need the text of the assert statement.  Is there another way I can get it when I have a cython test running?

thanks,  Walt 

Stefan Behnel

unread,
Mar 17, 2022, 3:19:18 AM3/17/22
to cython...@googlegroups.com
walt3k schrieb am 17.03.22 um 02:07:
My guess is that the "traceback" module in Python simply ignores files that
don't end in ".py".

Either actually use ".py" as extension for your Cython module (and then
stick to Python syntax in it), or read the code line yourself. The first
element in the sequence is the file name, the second the line number. Seems
easy.

Stefan

walt3k

unread,
Mar 18, 2022, 3:33:33 AM3/18/22
to cython-users
It was.  Thanks for the idea/workaround!

Walt.
Reply all
Reply to author
Forward
0 new messages