VRED freezes when executing a script

VRED freezes when executing a script

Anonymous
Not applicable
712 Views
2 Replies
Message 1 of 3

VRED freezes when executing a script

Anonymous
Not applicable

Hi,

i am using VRED Pro 2021 [13.0.0.10349] and want to import external data via sockets. Therefore i wrote the following python script: 

 

import socket
import threading

SERVER = socket.gethostbyname(socket.gethostname())
PORT = 5051
ADDR = (SERVER, PORT)
FORMAT = 'utf-8'
DISCONNECT_MESSAGE = "!DISCONNECT"
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(ADDR)

def handle_client(connaddr😞
    print(f"[NEW CONNECTION] {addr} connected.")
    connected = True
    while connected:
        msg = conn.recv(8192).decode(FORMAT)
        if msg == DISCONNECT_MESSAGE:
            connected = False
        print(f"[{addr} {msg}]")
    conn.close()

def start():
    server.listen()
    print(f"[LISTENING] Server is listening on {SERVER}")
    while True:
        conn, addr = server.accept()
        thread = threading.Thread(target=handle_client, args=(conn, addr))
        thread.start()
        print(f"[ACTIVE CONNECTIONS] {threading.activeCount() -1}")

print ("[STARTING] server is starting")
start()

 

The script works. I tested it seperatly. Whenever i try to run it, the script-editor and VRED itself freeze.

Does anyone know why?

0 Likes
Accepted solutions (1)
713 Views
2 Replies
Replies (2)
Message 2 of 3

sinje_thiedemann
Autodesk
Autodesk
Accepted solution

Hi,

it looks like your start() method is blocking the main thread.

Scripts are executed in VRED's main thread. So the gui and everything will be blocked/frozen if a script blocks it.

Try running start() in a separate thread, as you're already doing for the connections.

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you very much. That solved my problem!

0 Likes