0
$\begingroup$

I'm trying this answer approach, yet blender --python blender_server.py opens blender as blank (grey window, not even splash screen).

Pasting the script with Alt+P afterwords blender --factory-startup --verbose -1 freezes blender completely. Only killall blender stops blender. No errors at all.

  • Linux
  • Blender 3.10 or 2.93

blender_server.py:

# Script to run from blender:
#   blender --python blender_server.py

PORT = 8081
HOST = "localhost"
PATH_MAX = 4096


def execfile(filepath):
    import os
    global_namespace = {
        "__file__": filepath,
        "__name__": "__main__",
    }
    with open(filepath, 'rb') as file:
        exec(compile(file.read(), filepath, 'exec'), global_namespace)


def main():
    import socket

    serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    serversocket.bind((HOST, PORT))
    serversocket.listen(1)

    print("Listening on %s:%s" % (HOST, PORT))
    while True:
        connection, address = serversocket.accept()
        buf = connection.recv(PATH_MAX)

        for filepath in buf.split(b'\x00'):
            if filepath:
                print("Executing:", filepath)
                try:
                    execfile(filepath)
                except:
                    import traceback
                    traceback.print_exc()


if __name__ == "__main__":
    main()


$\endgroup$

1 Answer 1

3
$\begingroup$

You have two joint components to a problem here. One is that you are not passing the -b flag first, so a window does open. The other is that the script has a loop in it that will hold blender indefinitely, so of course the window never responds.

$\endgroup$
1
  • $\begingroup$ Thank you. I don't want it in background hence no need for -b or --background $\endgroup$
    – jjk
    May 22, 2022 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .