multithreading, pipes, data exchange with other software

Hey there,

I am searching for a good way to exchange data between blender python and other software.
I tried to use os pipes and multithreading but it seems that than another blender instance get started when started a new thread. That is not what I want.

Is there another way you would suggest to exchange information between blender and other software?

I also thought about sockets or a database. Anyone has experience with this?

I saw this on Blendernation but didn’t realize what it is. And didnt watch. seems exactly what i am looking for. Thanks! I will check it! Seems a bit of overload to me. But maybe this is the way to go.

The inter-process communication (IPC) method that you use will depend a lot on what kind of data you are passing. i.e. Passing small, infrequent messages makes sense to do one way but large, continuous streams work better with other technologies.

To really make a suggestion, more info is needed about the characteristics of the data you are passing.

Hey there,

i wanted to use it for the exchange of render relevant data. Not big data streams, more like status updates, render progress, program settings and further. so not more than arrays or variables.

That can be a bit tricky. There are a few application handlers for this kind of information. The question is where to put it. The easiest way is to just open some log file and write the info there. If you need more complicated “data”, you convert dictionaries to json data and log these.

I wouldn’t use stdout for communication between other processes and blender as a child, because blender and its addons print all sorts of stuff there.

i thought about this text/logfile thing. what about problems when blender and another software are reading or writing the file in the same moment? is there a way in python to lock the file?

You don’t need to lock the file. If multiple processes write to the same log file, they can just open it in “append” mode. You can also use the Python logging mechanisms for further fanciness.

There may also no need for multiple processes to write to the same file… just let them write to different files.

Reading log files which are being written is normally no problem. You may get a truncated final line every now and then, but not really a problem.