SimpleXMLRPCServer + 3dsmax 2016 + Python = freeze?

Hi,

I am trying to use SimpleXMLRPCServer with 3dsmax.
For this :

  1. I create a file c: oto.py
    In this file, i write :
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)

# Create server
server = SimpleXMLRPCServer(("localhost", 8000),requestHandler=RequestHandler)
# Run the server's main loop
server.serve_forever()
  1. In 3dsmax, i execute :
python.ExecuteFile "C:/toto.py"

Problem : 3dsmax is freezing.

What is wrong ?

Thank you,
Damien

Add all inside a thread give me nothing :

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
import thread

# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/RPC2',)

# Create server
def dispatchForever(x):
    server = SimpleXMLRPCServer(("localhost", 8000),requestHandler=RequestHandler)
    # Run the server's main loop
    server.serve_forever()
    
thread.start_new_thread(dispatchForever, (None,))

Because the doc tells :

NOTE: Python scripts run in MAXScript are not thread-safe. Python commands are always executed in the main 3ds Max thread. You should not attempt to spawn separate threads in your scripts (for example, by using the Python threading module).

3ds Max isn’t freezing. You asked it to run a listen server on its main thread and it is doing just that, preventing the main thread from doing anything else. As you noted in your second post 3ds Max does not cleanly support threading in its Python implementation - even though the threading module is included. The single threaded nature of Autdoesk’s Python implementation in 3ds Max and Motion Builder limits the ability to use them to create listen servers to facilitate data interchange with other applications. It’s frustrating, I know. I’ve been wanting to do something similar to what you are attempting.

So they is…no solution ? :no:
Even with Max script or another language ? (i want just a xml rpc server)

It works using .NET. I created a simple HTTP server and have it trigger an event on an incoming request, which is wired to a max script function. The only really annoying problem is that you cannot use all Max Script commands within the event (Maybe someone knows how to handle this?). For example, resetting Max does not work, when trying to do it from within the max-script event handler.

My solution is to pass the incoming command/code on to a global variable and then have a .NET ticker poll that variable and execute its code. It’s a bit hacky, but at least Max doesn’t throw “unspecified error” message boxes any more. You can probably make things less global - i.e. a bit more protected - by using Max Script structs. Once the ticker sees that a new command/code arrived, it uses “execute” to run the received command/code.

One problem is that the solution depends on the ticker interval. i.e. unless there’s a message queue it is possible to lose commands, if they arrive quickly after each other. However, using HTTP, I can receive entire script blocks in Max and execute them, so that’s maybe not that big of a problem.