0

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()

jjk
  • 980
  • 4
  • 18

1 Answers1

3

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.

TheLabCat
  • 6,219
  • 2
  • 14
  • 28