Want a strange XML RPC server

L

Laszlo Nagy

Hi,

I would like to have a strage XML RPC server. It should use one main
thread for all connections.

I have some code like this (using a custom RPC server class):


server_address = (LISTEN_HOST, LISTEN_PORT) # (address, port)
server = mess.SecureXMLRPCServer.SecureXMLRPCServer(
server_address,
RequestHandler,
KEYFILE,CERTFILE,
allow_none=True,
logger =
servicelog.getLogger('SecureXMLRPCServer',filename=LOGFILENAME),
logRequests=False,
stop_requested = stop_requested
)
rpcserver = RPCServer() # Object containing public RPC methods.
server.register_instance(rpcserver)

It works perfectly.

Now here is the tricky part. I would like to send back events. It is
implemented by an RPC callback:

#1. client calls server.get_event()
#2. server waits until the event happens (or until a given timeout)
#3. server returns the event (if any)

The clients are running on multiple threads, and the idea is that any
client can send an event by calling server.send_event(event).

That event will be returned to another client by the server. Since the
clients are blocking (waiting for the RPC call to return), events will
go from one client to another immediatelly (through the rpc server).
This goes through different kinds of proxies, and can be used from
different programming languages (Python and PHP clients, in my case...)

The problem is that in #2, waiting for the event to happen inside the
RPC server's handler method will block all other connections to the RPC
server.

Preferred solution: The get_event() method should run in a different
thread inside the server, and return the event to its xmlrpc client from
that thread. However, all other methods should use one main thread. I
would like to implement this as a decorator like:


class RPCServer(object):
"""Object containing public RPC methods."""
def method1(self,arg1):
.....
def method2(self,arg1):
.....
def method3(self,arg1):
.....

@nonblocking
def get_event1(self):
try:
# Wait for 10 seconds until an event is available.
return self.asinharvester.queued_events1.get(True,10)
except Queue.Empty:
return None # Indicates that there was no queued event.

@nonblocking
def get_event2(self):
try:
# Wait for 10 seconds until an event is available.
return self.asinharvester.queued_events2.get(True,10)
except Queue.Empty:
return None # Indicates that there was no queued event.


Is this possible? I have no idea how to write this "nonblocking" decorator.

Thanks,

Laszlo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top