0

I need to create and spawn several jsonrpc servers instances, listening in different ports, and spawning them from one class instance. In the code, I have a method which create a jsonrpc server and execute its run_forever method:

def attach_server(datos):
    server = SimpleJSONRPCServer((datos.url, datos.port))
    server.register_introspection_functions()
    server.register_instance(datos)

    # Run the server's main loop
    print 'running server in url:{} ,in port:{}'.format(datos.url,datos.port)
    server.serve_forever()  

Now, this function is invoked from a class instance which tries to create Server1, server2, serverN.
i.e.

Server1 = attach_server(datos1) #datos1.url = 'localhost', datos1.port = 4044
Server2 = attach_server(datos2) #datos2.url = 'localhost', datos2.port = 8088

My question is... How can I create this Server1, Server2 each one running on different processes? I need to avoid the serve_forever() forever loop which only allows me to run the first server.

I have tried using multiprocesses but I can't figure it out how to fork the process for each server. I tried something like this:

p = Process(name= 'deamon {0}'.format(data.port), target = attach_server(datos))
p.daemon = True
p.start()

Note that the target parameter in Process, is attaching the jsonrpc server that is running forever, also avoiding to start the second server. I guess I need to fork but I can't figure it out how/where/which tool is the correct one to use.

Any help, is welcomed! thanks

Luchux
  • 803
  • 1
  • 7
  • 17

1 Answers1

0

Well, answering my own question... I was calling the function that create each server instead of passing its reference ( name = 'whatever', target = attach_server, args = (datos, ) would be the right actual parameters.

HEADACHE with this silly mistake :) spanish chocolate is bad

tkz stackoverflow let you answer yourself after 8hs of your stupid post.

Luchux
  • 803
  • 1
  • 7
  • 17