Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52179 > unrolled thread

To make simpleXMLRPC support multi-thread

Started byZhang JiaQiang <zhangjiaqiang@gmail.com>
First post2013-08-08 02:03 -0700
Last post2013-08-09 08:34 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  To make simpleXMLRPC support multi-thread Zhang JiaQiang <zhangjiaqiang@gmail.com> - 2013-08-08 02:03 -0700
    Re: To make simpleXMLRPC support multi-thread dieter <dieter@handshake.de> - 2013-08-09 08:34 +0200

#52179 — To make simpleXMLRPC support multi-thread

FromZhang JiaQiang <zhangjiaqiang@gmail.com>
Date2013-08-08 02:03 -0700
SubjectTo make simpleXMLRPC support multi-thread
Message-ID<f85ed284-12bf-404c-b141-92bfe8d88261@googlegroups.com>
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()
 
 
 

[toc] | [next] | [standalone]


#52249

Fromdieter <dieter@handshake.de>
Date2013-08-09 08:34 +0200
Message-ID<mailman.388.1376030081.1251.python-list@python.org>
In reply to#52179
Zhang JiaQiang <zhangjiaqiang@gmail.com> writes:

> I try to use simpleXMLRPC and support request multithreads ,used 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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web