RESOLVED:TouchDesigner freeze after running Python script

Well, i writed a script on Python and tried to run it in TD. But TD freezed and i were need to restart TD. But when i try to run “print(“Hello World”)” script runs completely. Here is my code:

[i][b]from http.server import BaseHTTPRequestHandler, HTTPServer
import json
from json import loads, dumps
class MyRequestHandler(BaseHTTPRequestHandler):
“”“DOTA’s requests handler.”“”

def do_POST(self):
    """Receive DOTA2's informations."""
    length = int(self.headers['Content-Length'])
    body = self.rfile.read(length).decode('utf-8')
    self.parse_payload(body)
    self.send_header('Content-type', 'text/html')
    self.send_response(200)
    self.end_headers()

# Parsing and actions
def parse_payload(self, payload):
    """Search payload."""
    parsed_string = json.loads(payload)

def log_message(self, format, *args):
    return

class MyServer(HTTPServer):
“”“Server storing DOTA’s information.”“”
payload = None
server = MyServer((‘localhost’, 3000), MyRequestHandler)
try:
server.serve_forever()
except (KeyboardInterrupt, SystemExit):
pass
server.server_close()[/b][/i]

Hey,

from what I see your server is blocking the thread from continuing to run resulting in the freeze. To run a webserver you would have to put it in it’s own thread. Have a look at the Web Extension in Palette>Tools>WebCOMP to see how that might be done. It uses the queue and threading Libraries to allow for a persistent connection to be open in the background.

Best
Markus