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()
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()