Running multiple servers with multiple processes

Typically: "How do I... ", "How can I... " questions
Post Reply
Posts: 25
Joined: 09 Aug 2017, 18:52

Running multiple servers with multiple processes

Post by johnrowlay » 16 Oct 2018, 19:19

I want to run multiple simulation servers in parallel, with each running on its own process. To do this, I am using the "Process" class from the Python "multiprocessing" module. Each "Process" object calls a function, which itself then launches a V-Rep server on a new port.

Here is my main outer loop, which creates 10 process:

Code: Select all

for i in range(10):
    port_num = 19990 + i
    sim_process = multiprocessing.Process(target=run_vrep, args=(port_num))
And here is what each process runs:

Code: Select all

def run_vrep(port_num):
    vrep.simxStart('', port_num, True, True, 5000, 5)
    args = ['', '-gREMOTEAPISERVERSERVICE_' + str(port_num) + '_FALSE_TRUE', 'scene_file.ttt']
    server_process = Popen(args, preexec_fn=os.setsid)
So my first question is: Is this the correct way to be launching multiple V-Rep servers in parallel?

Now for my second questions. When I run this code, it does indeed launch several V-Rep servers, each appearing as a new window / GUI on my desktop. However, I am now having trouble using the remote API; specifically, the "simxCallScriptFunction" function.

In my scene, I have a child script called "remoteAPI", and this has several functions which I want to be able to call from my Python client. One of these functions, "testFunction()", just prints out something to the screen. From my Python client, if I call:

Code: Select all

vrep.simxCallScriptFunction(client_id, 'remoteAPI', vrep.sim_scripttype_childscript, 'testFunction', [], [], [], bytearray(), vrep.simx_opmode_blocking)
Then the return code shows an error: "vrep.simx_return_remote_error_flag". So it seems that my client cannot connect to the "remoteAPI" child script.

So my second question is: What should I do to enable this remote API script on the server?

I have read the instructions at ... erSide.htm, and tried the following. Since I am running multiple servers on different ports, I have commented out everything in "remoteApiConnections.txt", and I want to start a temporary remote API server service for each server. To do this, at the top of my "remoteApi" child script, I have the following function:

Code: Select all

function sysCall_init()
    print('Running initialisation')
But there are two issues. Firstly, I never see "Running initialisation" printed out anywhere, so it seems that this function is never run at all. Secondly, what should I replace "19990" with, such that each server can connect to the correct client port number? Should I send the port number as an argument to "sysCall_init()"? And how can I do this?

Thank you!

Site Admin
Posts: 7222
Joined: 14 Dec 2012, 00:25

Re: Running multiple servers with multiple processes

Post by coppelia » 23 Oct 2018, 06:29


about your questions:

I think you do everything right. The only problem is that you are trying to call a script function inside of a child script. And a child script is only initialized during simulation. So unless simulation has started, sysCall_init() will not be called and you won't be able to call script functions via simxCallScriptFunction(..).

I would use a customization script instead. Customization script are initialized as soon as the scene/model is loaded.

You can create a temporary remote API server service from within your init in the customization script, but better would be to create a continuous remote API server service from your command line with the -gREMOTEAPISERVERSERVICE_NN option. Just make sure to specify different port numbers for your different V-REP instances.


Post Reply