Python console and external call

Hello,

We use an internal software in our pipeline that allows us to control various applications. Developed in Python, it communicates through an RPC interface (using zmq).

I integrated it into Blender in the form of an addon without any issues.

However, the problem arises when we launch the Python console.
More specifically, when modifying an object, such as its position.

After that, my internal calls via RPC fail with the following error:
ReferenceError: StructRNA of type ConsoleExec has been removed.

I don’t understand what’s happening.
Is the Python runtime undergoing an initialization or a reload?
Is another Python runtime being executed?

Any ideas on how to resolve this?
Thank you for your help.

Not enough information about your code, error, environment, etc.
Did you installed the pzmq inside the Blender’s Python environment?

1 Like

Hi Secrop,

Thanks for your response.

I am using Windows 10, Blender 4.2.1 LTS.
When deploying our pipeline tool, a script shares the necessary environment for Blender (with pyzmq).
So, I have two independent applications, both running Python 3.11, based on the same libraries.

All the communication works very well; I can open scenes and manipulate them.
I can make my own manipulations through the Blender interface.
And I can relaunch communications without any issues.

However, if I need to launch the Python console, I encounter problems.
I can explore bpy.context or bpy.data, and the RPC communication works fine.

But as soon as I modify an object - via the console -, the RPC communication fails with the error: ReferenceError: StructRNA of type ConsoleExec has been removed.

I do receive the command in my RPC thread, but as soon as I make the function call—in the main thread—I get the error.

I have the impression that opening the console manipulates the Python context or something along those lines.

I don’t understand why I’m attempting to access the ConsoleExec structure, as I’m not interacting with it in my implementation.

Hello, I suggest you never store pointers to objects using the python API. They are invalidated semi-randomly (on save, on undo/redo, etc.). Object names are enforced to be unique so you can store object names instead of object pointers. You just need to ensure you have some logic to keep the stored names if you rename your objects.

1 Like