Reputation: 270
I am having a problem calling a shared c library from python. The library loads fine and one of the 3 functions exposed are callable, and work as expected; however, when adding another function to the library, I found that the other two do not work. What happens is that python hangs on the actual function call and just spins while doing nothing. Both the python side and the c side have detailed logging, and I can tell that the function in the library isn't even starting because none of the debug files are being written.
Below is a small snippet of the code in question:
This is the c code sample function that is failing:
int genTest(char* filePath)
{
infoPrint(filePath, 2);
return EXIT_SUCCESS;
}
this is the python that I am calling it with:
import ctypes as C
lg.create_log_entry('loading dll... from ' + str(lib_path) + str(lib_name))
myclib = C.CDLL(lib_path + lib_name)
lg.create_log_entry('loaded')
genTest = myclib.genTest
genTest.argtypes = [C.c_char_p]
genTest.restype = C.c_int
lg.create_log_entry('test start')
res = genTest(C.c_char_p(str(source_as_image)))
certirxlogging.create_log_entry('test successful')
This code gets to writing 'test start' and hangs. Like I said, this works fine on another function in the library elsewhere in the python code, and python isn't throwing me any errors, so, I am unable to debug anything. Any ideas?
Upvotes: 1
Views: 1529
Reputation: 270
So, I figured out why it was failing. Something in that call to my infoPrint function was throwing a segfault.
The reason that cause my program to hang was that I was using python's Multiprocessing library to run this function in a separate process and communicating to it with pipes. The parent process was polling the pipe with a timeout to get a return value that never came because of the sudden crash.
Thanks for the help in getting over this little bump, now I can (hopefully) figure out what is going wrong with the c code.
Upvotes: 2