← Back to team overview

sikuli-driver team mailing list archive

[Question #228924]: How to terminate a script which involves SimpleXMLRPCServer gracefully

 

New question #228924 on Sikuli:
https://answers.launchpad.net/sikuli/+question/228924

Is there any graceful way to terminate test scripts  which involves XMLRPC communication between server & client?
The client part will exit gracefully after the test ends.. It seems the serve_forever() in the ServerThread class at the server side prevents the termination of it...Any solution please to overcome this issue.

Sample code goes here:

Client Code:-

from sikuli.Sikuli import *
import math
import xmlrpclib
import os 
import sys
import unittest
from SimpleXMLRPCServer import SimpleXMLRPCServer
import threading

import HTMLTestRunner 
reload(HTMLTestRunner)
dir = "D:\MyWorkSpace\DellReportTest"
fp = file(os.path.join(dir, "TestResultDell.html"), "wb")


class ABC():
    def display(self):
        print "Inside Display ABC"
        return True
   
abc_client = xmlrpclib.ServerProxy("http://192.168.173.231:8000";)  


class MachineABCTest(unittest.TestCase):
    def setUp(self):
        pass
    def test_ABC(self):
        abc = ABC()
        abc.display()
        wait(5)
        x1 = abc_client.add()       # a method which resides in MachineXYZTest
        wait(5)
    def tearDown(self):
        print "Inside tearDown"
        wait(10)


suite = unittest.TestLoader().loadTestsFromTestCase(MachineABCTest)
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, verbosity=2)
runner.run(suite)
fp.close()


Server Code:-

from sikuli.Sikuli import *
import xmlrpclib
import os 
import sys
import unittest
from SimpleXMLRPCServer import SimpleXMLRPCServer 
import threading

import HTMLTestRunner 
reload(HTMLTestRunner)
dir = "D:\MyWorkSpace\Server"
fp = file(os.path.join(dir, "ServerReport.html"), "wb")


class XYZ():
    def display(self):
        print "Inside Display XYZ"
        return True
    def sum(self):
        print "inside sum"
        return True


class MachineXYZTest(unittest.TestCase):
    def setUp(self):
        pass
    def test_XYZ(self):
        xyz = XYZ()
        disp = xyz.display() 
        wait(5)
    def tearDown(self):
        print "Inside tearDown"
        wait(10)
        
class ServerThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.xyz_server = SimpleXMLRPCServer(("192.168.173.200", 8000))
        self.xyz_server.register_instance(XYZ()) # method add  will get registered

    def run(self):
        self.xyz_server.serve_forever()

xyz_server = ServerThread()
xyz_server.start()
wait(5)

suite = unittest.TestLoader().loadTestsFromTestCase(MachineXYZTest)
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, verbosity=2)
runner.run(suite)
fp.close()



Here the client side scripts terminates gracefully but the server side script doesn't.


Thanks.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.