Anvil Blender Uplink Crash

What I’m trying to do:
Trying to call some anvil.server.callable functions from the browser in blender

What I’ve tried and what’s not working:
While calling simple functions like printing a message inside the blender console works fine, when doing more complex operations like opening a file, or appending data from other files, blender will just crash, without any message, even if I start blender through the cmd line, I still don’t get any crash messages.

It’s strange because very rarely the code sometimes runs till the end, but sometimes it just crashes.

If I run the code directly from blender, it always works.

So I am wondering if anyone has experience setting anvil up with blender, if you encountered these problems?

Bellow is a simplified version of the function in am trying to run inside blender

Code Sample:

@ anvil.server.callable("load_shot_" + ID)
def load_shot(shotInfo):
    
    layers = ['Int_Rearliner_STD', 'INT_Roof_Std', 'INT_Trunk_Std', 'INT_DashboardButtons_2', 'INT_Floor_Std', 'INT_Doors_1', 'INT_Mirror_1',
              'INT_Seats_2nd_2', 'INT_Seats_2nd_Headrests_1', 'INT_Seats_3rd_Std', 'INT_Seats_3rd_Headrests_1_Std', 'INT_Seats_1st_2', 'INT_Dashboard_2']

    path = "Z:\\01_Production_MB\\01_Library\\01_Products\\V260\\MY2022\\BLEND\\V260_MY2022.blend"

    with bpy.data.libraries.load(path) as (data_from, data_to):
        data_to.collections = [
            name for name in data_from.collections if name in layers]
    for collection in data_to.collections:
        try:
            bpy.context.scene.collection.children.link(collection)
        except:
            print(collection)

    zsu.link_collection_to_collection("Collection", collection)
     

I have never used Blender, but my guess is that when an anvil.server.callable is called, the function is executed in a new thread and Blender doesn’t like it.

Can you try to get the uplink to connect to the running instance of Blender and start a second script there?

Sorry I’m a bit of a newbie.

I think I am already starting the anvil uplink in the current instance of blender.

The anvil.server.callable function is inside an addon I wrote for blender. After i open blender i added a button to connect to the uplink server.

What I mean is to have the uplink running on its own python interpreter, not inside Blender. When the callable is executed, it should talk to Blender and tell Blender to start its own script.

I don’t know neither your environment nor Blender, so I don’t know how that talk will work.

If you are on Windows and Blender is a COM server I can try to help you, I do something similar with my uplink servers.

If you are on Linux or if Blender is not a COM server, then I don’t know.

Oh yes, that’s my backup plan, a little bit tight on time now, need to get something working.

So I switched to calling server functions from Blender. It’s enough for an MVP :smiley:

Gonna try running uplink in its on interpreter when have some time, to see if that works. Will update this thread.