Odd Python / C Library interaction - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Odd Python / C Library interaction (/thread-21672.html) |
Odd Python / C Library interaction - embedka - Oct-09-2019 I'm running a script from a Linux terminal with Python 3.6.8 and the script started failing when I tried to expand it with a function definition. I whittled it down to the basics and found that the device fails to connect when there is a function definition followed by a print statement in the code, but not when there's a print statement followed by a function definition. It doesn't even matter what's in the print and whether or not the function definition is used. This code successfully connects to (and disconnects from) the device: import DeviceInterface device_class = DeviceInterface.Device() print() def dummy_function_that_does_nothing(): pass with device_class: passThis code, which swaps the function definition and print statement, gives a device connection error: import DeviceInterface device_class = DeviceInterface.Device() def dummy_function_that_does_nothing(): pass print() with device_class: passThese examples are the exact file contents of the script being run (nothing added or omitted for this post). The DeviceInterface module is a ctypes wrapper around a C-based .so library. That library is not mine and I don't have rights to distribute it, but it's using Aravis v0.6.4. The connection failure is caused by a null pointer being returned from a call to arv_camera_new(). I would expect no difference between the 2 versions of code above. There seems to be something deeper going on in Python or Linux libraries that I don't understand. I suspect a memory issue in the library, but I do not understand how and why Python is exciting the error by changing what I thought was a meaningless part of the code. Other things I've tried
|