To make simpleXMLRPC support multi-thread

Z

Zhang JiaQiang

I try to use simpleXMLRPC and support request multithreads ,used ThreadingMixIn.

Why what I get from the console still blocking ?

launch the two clients at the same time,one finish, then begin the other, between them there is 15 sec.

Here is the console output on server windows:

Use Cc to exit
DEBUG:root:111111 request dir the directory(/)
DEBUG:root:block 111111 ...
nio102 - - [08/Aug/2013 15:35:17] "POST /RPC2 HTTP/1.0" 200 -
DEBUG:root:222222 request dir the directory(/)
DEBUG:root:block 222222 ...
nio102 - - [08/Aug/2013 15:35:32] "POST /RPC2 HTTP/1.0" 200 -


The following are the codes:

###### client 1111111 ##########
import xmlrpclib

proxy = xmlrpclib.ServerProxy('http://xx.xx.xx.xx:9000')
print proxy.dir_contents('/', '111111')


###### client 2222222 ###########
import xmlrpclib

proxy = xmlrpclib.ServerProxy('http://xx.xx.xx.xx:9000')
print proxy.dir_contents('/', '222222')



###### server ###################
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SocketServer import ThreadingMixIn
import logging

import os
import time


logging.basicConfig(level=logging.DEBUG)


def list_contents(dir_name, client):
logging.debug('%s request list the directory(%s)', client, dir_name)
logging.debug('block %s request for 15 sec...' % client)
time.sleep(15)
return os.listdir(dir_name)

class ListDirRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
def __init__(self, ip, port):
self.server = SimpleXMLRPCServer((ip, port), logRequests=True)
self.server.register_function(list_contents)

def active_server(self):
try:
print "Use Cc to exit"
self.server.serve_forever()
except KeyboardInterrupt:
print "exiting"

if __name__ == '__main__':
ip = 'xx.xx.xx.xx'
port = 9000
list_rpc = ListDirRPCServer(ip, port)
list_rpc.active_server()
 
D

dieter

Zhang JiaQiang said:
I try to use simpleXMLRPC and support request multithreads $B!$(Bused ThreadingMixIn.

Why what I get from the console still blocking ?

I am not sure - but, you fail to call the inherited "__init__" method
in your deriving class. This might things mess up.
...
class ListDirRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
def __init__(self, ip, port):
self.server = SimpleXMLRPCServer((ip, port), logRequests=True)
self.server.register_function(list_contents)

Usually, in a derived class's "__init__" method, you should
call the inherited "__init__" method.
 

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,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top