Example #1
0
    def testSingleIntegerArg(self):
        rpcserver = rpc.rpcserver(0)
        rpcserver.add_handler("echo", lambda o: o)

        _start_new_thread(rpcserver.serve_forever)
        try:
            rpcclient = rpc.rpcclient(rpcserver.port)
            self.assertRaises(Exception, rpcclient.flaterror, (18,))
        finally:
            rpcserver.shutdown()
            rpcserver.close()
Example #2
0
    def testExceptionOnHandlerFlattening(self):
        rpcserver = rpc.rpcserver(0)
        rpcserver.add_handler("flaterror", lambda o: object())

        _start_new_thread(rpcserver.serve_forever)
        try:
            rpcclient = rpc.rpcclient(rpcserver.port)
            self.assertRaises(Exception, rpcclient.flaterror, ("Hello",))
        finally:
            rpcserver.shutdown()
            rpcserver.close()
Example #3
0
    def testBasic(self):
        rpcserver = rpc.rpcserver(0)
        rpcserver.add_handler("cat", catTwoStrings)

        _start_new_thread(rpcserver.serve_forever)
        try:
            rpcclient = rpc.rpcclient(rpcserver.port)
            result = rpcclient.cat("Hello, ", "World!")
            self.assertEqual("Hello, World!", result)
        finally:
            rpcserver.shutdown()
            rpcserver.close()
Example #4
0
    def testMultipleHandlers(self):
        rpcserver = rpc.rpcserver(0)
        rpcserver.add_handler("cat", lambda s1, s2: s1 + s2)
        rpcserver.add_handler("len", lambda s1, s2: len(s1 + s2))

        _start_new_thread(rpcserver.serve_forever)
        try:
            rpcclient = rpc.rpcclient(rpcserver.port)
            result = rpcclient.cat("Hello, ", "World!")
            self.assertEqual("Hello, World!", result)
            result = rpcclient.len("Hello, ", "World!")
            self.assertEqual(len("Hello, World!"), result)
        finally:
            rpcserver.shutdown()
            rpcserver.close()
 def setUp(self):
     self.rpcserver = rpc.rpcserver(0)
     self.rpcserver.add_handler("cat", lambda s1, s2: s1 + s2)
     _start_new_thread(self.rpcserver.serve_forever)
     self.rpcclient = rpc.rpcclient(self.rpcserver.port)
This script is designed to be passed to scisoftpy.rpc's addHandler, see PythonRunScriptService.java
'''

import os, sys, threading

sys_path_0_lock = threading.Lock()
sys_path_0_set = False

import time
import os, sys
'''
Import the rpc part which we will use for workflows.
'''
import scisoftpy.rpc as rpc  #@UnresolvedImport
rpcserver = rpc.rpcserver(int(sys.argv[1]))


def isActive(dummy):
    return True


rpcserver.add_handler("isActive", isActive)


def runScript(scriptPath, inputs, funcName='run'):
    '''
    scriptPath  - is the path to the user script that should be run
    inputs      - is a dictionary of input objects
    '''
work in the following way
1. Set primitives from java, strings, doubles, int etc to be variables here
2. Set abtract datasets as numpy arrays
3. Run a user defined script

the script requires one argument which is the port to start the service on.

'''
import time
import os, sys

'''
Import the rpc part which we will use for workflows.
'''
import scisoftpy.rpc as rpc #@UnresolvedImport
rpcserver = rpc.rpcserver(int(sys.argv[1]))

'''
We tell scisoft the port to be used for plotting
'''
import scisoftpy.plot as plot
plottingPort = int(sys.argv[2]);

if (plottingPort>0):
    plot.setremoteport(rpcport=plottingPort)


def isActive(dummy):
    return True

rpcserver.add_handler("isActive",  isActive)