When running Python script that makes use of Cython and C++ and an unhandled exception occurs console output doesn't contain any useful information:
collecting ... Fatal Python error: Aborted
Current thread 0x00007f0c1f7ec000 (most recent call first):
File ".../test_program.py", line 29 in test_eval_simple
File ".../test_program.py", line 31 in <module>
File ".../venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 168 in exec_module
...
However if I attach C++ debugger and run the same script an exception information is being printed out which makes debugging much easier:
terminate called after throwing an instance of 'af::exception'
what(): ArrayFire Exception (Invalid input size:203):
In function af::dim4 getOutDims(const af::dim4&, const af::dim4&, bool)
In file src/backend/ArrayInfo.cpp:173
Invalid dimension for argument 1
Expected: ldims == rdims
In function af::array af::operator/(const af::array&, const af::array&)
Is it possible to instruct Cython/Python to produce a more meaningful message and print out C++ exception information by default?
Related
I created a f2py python interface for PITCON7 (pitcon7.f90). The interface exposes two functions pitcon and dge_slv from pitcon7.f90. dge_slv is passed as a callback to pitcon. However on executing a sample problem that invokes pitcon I get the error
Traceback (most recent call last):
File "pitcon_problem01.py", line 91, in <module>
result = run(30)
File "pitcon_problem01.py", line 58, in run
ierror, iwork, rwork, xr = pitcon(df, fpar, fx, ierror, ipar, iwork, liw, nvar, rwork, lrw, xr, dge_slv)
TypeError: interface.pitcon() argument 12 must be tuple, not fortran
The pitcon7.pyf file is posted to pastebin
The sample problem pitcon_propblem01.py has also been posted to pastebin . This is the python equivalent of the Fortran pitcon7_test1.f90 from the same upstream source, linked above.
I do not see why the f2py interface expects the callback to be a tuple, since there does not seem to be any argument mismatch.
I have developed a Python script to reference another Python file with functions to compute KPIs. Then, using the main file, the KPIs are cleaned and ordered and finally outputted to a word doc. In the process I am also referring an Excel file to provide further user-desired inputs.
Now I want to be able to just use one line to run the entire file. I have tried and have in the past successfully used:
exec(open("binary2.py").read())
However, with this file, I am running into a certain error which I am not facing when I simply run binary1.py on its own. As in, error happens only using the exec command.
AttributeError Traceback (most recent call last) in
----> 1 exec(open("binary2.py").read())
in
~\Desktop\Model_Validation\Playbook XLS and Jupyter
Notebook\BinaryKPI_PythonFunctionsV3.py in data_vars(df1, target)
662 stack = traceback.extract_stack()
663 filename, lineno, function_name, code = stack[-2]
--> 664 vars_name = re.compile(r'((.?)).$').search(code).groups()[0]
665 final = (re.findall(r"[\w']+", vars_name))[-1]
666
AttributeError: 'NoneType' object has no attribute 'groups'
There is a function which I am calling in the binary2 file which calls for the Traceback. It seems this Traceback is not getting carried over while using exec command.
I also tried:
source = open("binary2.py").read()
code2 = compile(source, filename, 'exec')
exec(code2)
but to no benefit.
Any ideas appreciated.
Thanks,
Ansh
Edit: The code generating an error while running the exec command runs fine while running the py file directly:
I am porting CPython to Emscripten, and it builds successfully. However, when I try to run the python.asm.js through Node.js, I get a very strange error inside the Py_InitializeEx(0) call:
Traceback (most recent call last):
File "/lib/python2.7/site.py", line 62, in <module>
import os
File "/lib/python2.7/os.py", line 44, in <module>
from posix import *
TypeError: 'NotImplementedType' object does not support indexing
The error is generated from PySequence_GetItem in Objects/abstract.c, but I don't understand how the execution gets there. If I do import posix before the line that causes the error, the import posix statement finish successfully, and I can call functions in the posix module. Thus, the error is related to from <module> import * line. How is PySequence_GetItem related to from <module> import * statement, and what could be the reasons for the error?
If you want to reproduce the problem, I released the code on GitHub
While investigating what is going wrong, I switched off the optimization (compiled and linked with -O0). The resulting JS executable also failed, but with a different error:
Invalid function pointer '495' called with signature 'iii'. Perhaps this is
an invalid value (e.g. caused by calling a virtual method on a NULL pointer)?
Or calling a function with an incorrect type, which will fail? (it is worth
building your source files with -Werror (warnings are errors), as warnings can
indicate undefined behavior which can cause this)
This pointer might make sense in another type signature:
ii: _dict_keys iiii: 0 i: undefined iiiii: 0 viii: 0 vii: 0 vi: 0 v: 0
495
495
I looked through Emscripten's settings.js for options related to function pointers, and found EMULATE_FUNCTION_POINTER_CASTS which fixed the problem.
Hi i am using python multiprocessing module and the problem is when i get an error from a code that has been executed in another thread, the Traceback is only pointing to multiprocessing/pool.py", line 520 instead of the line number of what caused the error exactly.
Traceback (most recent call last):
File "analyzer.py", line 196, in <module>
for ret in pool.imap(ProcessRow, rows):
File "/usr/lib64/python2.6/multiprocessing/pool.py", line 520, in next
raise value
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
so line 196 in analyzer.py is when i call for ret in pool.imap(ProcessRow, rows):
so it's completely not helpful....Any advice ?
The error is raised from ProcessRow() or some function called by it (why is your function CamelCaseUpper?).
You are not getting a proper stack trace, because the exception is actually pickled from the subprocess (hence the name of the module: multiprocessing) your code is executing in and is then raised again in the manager process. Hence the stack trace shows up as if it was local (while it is actually an exception raised in the subprocess).
The preferred way of dealing with this seems to be to catch the exception in the forked of code and printing a proper stacktrace from there.
Basically, I want to read the CPU temperature with Python. Please explain in layman's terms as I have never done this on Windows before nor have I had to work with wmi.
This is what I have at the moment:
import wmi
w = wmi.WMI(namespace="root\wmi")
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
print temperature_info.CurrentTemperature
(I got this code from this thread: Accessing CPU temperature in python)
However, on running the script, I get this error:
Traceback (most recent call last):
File "C:\Users\Ryan\Desktop\SerialSystemMonitor", line 4, in <module>
temperature_info = w.MSAcpi_ThermalZoneTemperature()[0]
File "C:\Python27\lib\site-packages\wmi.py", line 819, in query
handle_com_error ()
File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error
raise klass (com_error=err)
x_wmi: <x_wmi: Unexpected COM Error (-2147217396, 'OLE error 0x8004100c', None, None)>
What can I do to get this to work?
According to the MSDN page on WMI Error Constants, the error you have received is:
WBEM_E_NOT_SUPPORTED
2147749900 (0x8004100C)
Feature or operation is not supported.
Presumably, then, your CPU does not provide temperature information through WMI. If your CPU doesn't expose this information, you're probably out of luck, at least as far as a straightforward solution in Python goes.
I assume you've tried the other option given in the answer you linked, using Win32_TemperatureProbe(); if you haven't, try it.
Just execute as Admin. It's work for me.