Skip to content

Instantly share code, notes, and snippets.

@mcchae
Created December 18, 2014 02:32
Show Gist options
  • Save mcchae/280afebf7e8e4f491a66 to your computer and use it in GitHub Desktop.
Save mcchae/280afebf7e8e4f491a66 to your computer and use it in GitHub Desktop.
Python non-blocking XML-RPC
#!/usr/bin/env python
#coding=utf8
"""
====================================
:mod: 테스트용 blocking XML-RPC 서버
====================================
.. moduleauthor:: 채문창 <[email protected]>
.. note:: GNU
설명
=====
테스트용 blocking XML-RPC 서버
"""
##########################################################################################
import time
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
##########################################################################################
class TestSvc(object):
def ping(self, pid, _sleep=0):
for i in xrange(_sleep):
print "[%d] %d" % (pid, i)
time.sleep(1)
return True
##########################################################################################
def doSvc():
mgr = TestSvc()
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/TestSvc')
server = SimpleXMLRPCServer(('0.0.0.0', 9000),
requestHandler=RequestHandler,
logRequests=False,
allow_none=True,
)
server.register_introspection_functions()
server.register_instance(mgr)
server.serve_forever()
##########################################################################################
if __name__=='__main__':
doSvc()
#!/usr/bin/env python
#coding=utf8
"""
====================================
:mod: 테스트용 non-blocking XML-RPC 서버
====================================
.. moduleauthor:: 채문창 <[email protected]>
.. note:: GNU
설명
=====
테스트용 non-blocking XML-RPC 서버
"""
##########################################################################################
import time
from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
##########################################################################################
class TestSvc(object):
def ping(self, pid, _sleep=0):
for i in xrange(_sleep):
print "[%d] %d" % (pid, i)
time.sleep(1)
return True
##########################################################################################
def doSvc():
mgr = TestSvc()
from SocketServer import ThreadingMixIn
class SimpleThreadXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
pass
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/TestSvc')
server = SimpleThreadXMLRPCServer(('0.0.0.0', 9000),
requestHandler=RequestHandler,
logRequests=False,
allow_none=True,
)
server.register_introspection_functions()
server.register_instance(mgr)
server.serve_forever()
##########################################################################################
if __name__=='__main__':
doSvc()
#!/usr/bin/env python
#coding=utf8
import os
import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://localhost:9000/TestSvc")
print "[%d] TestSvc.ping(5)=%s" % (os.getpid(), proxy.ping(os.getpid(), 5))
#!/bin/bash
python xmlrpc_client.py &
python xmlrpc_client.py &
python xmlrpc_client.py &
python xmlrpc_client.py &
python xmlrpc_client.py &
FAIL=0
sleep 2
for job in `jobs -p`; do
wait $job || let "FAIL+=1"
done
if [ "$FAIL" == "0" ]; then
echo "Done!"
else
echo "FAIL! ($FAIL)"
fi
@1nsunym
Copy link

1nsunym commented Sep 21, 2018

I don't know why or how but it works like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment