Hey
So this is my init file>
@persistent
def load_handler(dummy):
print("Load persistent Timmer: ", dummy)
bpy.app.timers.register(utilities.runInternalTimer)
def register():
bpy.app.handlers.load_post.append(load_handler)
inside utilities.py I have
def runInternalTimer():
while not execution_queue.empty():
function = execution_queue.get()
function()
return 0.5
But I keep on crashing when this is my command>
bpy.ops.mesh.primitive_plane_add(size=500, location=(0, 0, 0))
The queue is being popualated from my thread running outside blender, and i use queue/timmer to push them to run inside blender thread. But it crashes with
Error : EXCEPTION_ACCESS_VIOLATION
Address : 0x00007FF7D0B4E69A
Module : C:\Program Files\Blender Foundation\Blender 2.83\blender.exe
Any hints?
I think this is just unsupported: https://docs.blender.org/api/current/info_gotcha.html#strange-errors-using-threading-module
Why are you trying to use threading? This looks like a case of pre-mature optimization.
Well I’m using blender timmer and proper queue approach. But that does not work, further reading jelded result that ops can not be run from timmers thus there is no way for me to run that function in current tate 
But why were you using a threading approach in the first place?
@Josephbburg Because I was some heavy processing in background and when it done I wanted it to push update to blender… but they cant use ops :- ) Even if I run them via timer/queue system in blender thread.
- Get it working first, if you haven’t gotten it to do exactly what you want (albeit slowly) you shouldn’t try to speed it up yet. Solve one problem at a time
- Perhaps you have a working script, but it is too slow. Maybe that’s because you are using
ops
! You shouldn’t use ops
in a script if you have a choice. It’s not as fast, not as Pythonic, and not as robust. Use the bpy.data
API!
And finally, threading isn’t a magic bullet. You can write fast Python scripts without using threading if you structure the code correctly, (and of course it depends on what you are doing. Some things should just be done in fast, compiled languages) and threading won’t necessarily make a slow script fast, either! I think it should be avoided, because it’s far more complex than a single thread solution. Keeping the script on a single thread makes it easier to solve one problem at a time, and that’s a good habit.
Thanks for the hints. But as far as I can tell I can’t call bpy.ops.mesh.primitive_plane_add
from blender timmer, so unless you know alternative command for it then I think its not possible atm
Use Bmesh to create the new object, example on this page:
https://docs.blender.org/api/current/bmesh.html
Cheers, Clock.