Beispiel #1
0
    def test_client_server_full_flow(self):
        storage = MemoryStorage()
        self.server = msgpackrpc.Server(SifrServer(storage),
                                        unpack_encoding='utf-8')
        port = get_free_port()
        self.server.listen(msgpackrpc.Address('127.0.0.1', port))
        self.server_thread = threading.Thread(target=self.run_server)
        self.server_thread.start()
        time.sleep(0.1)

        cli = RPCClient('127.0.0.1', port)
        cli.incr("foo", 1)
        self.assertEqual(1,
                         storage.count(Hour(datetime.datetime.now(), ["foo"])))
        cli.incr("bar", 1, ["minute"])
        self.assertEqual(0,
                         storage.count(Hour(datetime.datetime.now(), ["bar"])))
        self.assertEqual(
            1, storage.count(Minute(datetime.datetime.now(), ["bar"])))
        self.assertEqual(1, cli.count("foo", datetime.datetime.now(), "hour"))
        cli.incr_unique("foo", "test")
        self.assertEqual(
            1, storage.cardinality(Hour(datetime.datetime.now(), ["foo"])))
        self.assertEqual(
            1, cli.cardinality("foo", datetime.datetime.now(), "hour"))
        cli.track("foo", "test")
        self.assertEqual(
            set(["test"]),
            storage.uniques(Hour(datetime.datetime.now(), ["foo"])))
        self.assertEqual(set(["test"]),
                         cli.uniques("foo", datetime.datetime.now(), "hour"))
Beispiel #2
0
 def run():
     try:
         self._server = msgpackrpc.Server(self)
         self._server.listen(msgpackrpc.Address(*bind_address))
         self._server.start()
     except Exception as e:
         self.exception(str(e))
Beispiel #3
0
def run_sum_server():
    class SumServer(object):
        def sum(self, x, y):
            return x + y

    server = msgpackrpc.Server(SumServer())
    server.listen(msgpackrpc.Address("localhost", 6000))
    server.start()
def main():
    print("Initialise Server...", flush=True)
    server = msgpackrpc.Server(Calculator())

    print("Start Server...", flush=True)
    port = 18800
    host = "localhost"
    server.listen(msgpackrpc.Address("localhost", 18800))

    print(f"Server is running on: {host}:{port}", flush=True)
    server.start()
Beispiel #5
0
    def setup_env(self):
        def _start_server(server):
            server.start()
            server.close()

        self._server = msgpackrpc.Server(TestMessagePackRPC.TestServer())
        self._server.listen(self._address)
        self._thread = threading.Thread(target=_start_server, args=(self._server,))
        self._thread.start()

        self._client = msgpackrpc.Client(self._address, unpack_encoding='utf-8')
        return self._client;
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()
    arg = parser.add_argument
    arg('path', nargs='?')
    arg('--center', action='store_true')
    arg('--pca', action='store_true')
    args = parser.parse_args()
    server = msgpackrpc.Server(
        Word2VecServer(path=args.path, center=args.center,
                       pca_center=args.pca))
    server.listen(msgpackrpc.Address('localhost', WORD2VEC_PORT))
    print('running...')
    server.start()
Beispiel #7
0
def serve(daemon=False):
    """Serve echo server in background on localhost.
    This returns (server, port). port is number in integer.

    To stop, use ``server.shutdown()``
    """
    for port in xrange(9000, 10000):
        try:
            addr = msgpackrpc.Address('localhost', port)
            server = msgpackrpc.Server(EchoHandler())
            print server
            server.listen(addr)
            thread = serve_background(server, daemon)
            return (addr, server, thread)
        except Exception as err:
            print err
            pass
Beispiel #8
0
def doRpcServer(port, stopTimeSec):
    class EchoHandler(object):
        def Echo123(self, msg1, msg2, msg3):
            return ("1:%s 2:%s 3:%s" % (msg1, msg2, msg3))
        def EchoStruct(self, msg):
            return ("%s" % msg)
    
    addr = msgpackrpc.Address(mylocaladdr, port)
    server = msgpackrpc.Server(EchoHandler())
    server.listen(addr)
    # run thread to stop it after stopTimeSec seconds if > 0
    if stopTimeSec > 0:
        def myStopRpcServer():
            server.stop()
        t = threading.Timer(stopTimeSec, myStopRpcServer)
        t.start()
    server.start()
Beispiel #9
0
def msgpack_server(sifrd, config):
    storage_type = config.get("storage")
    if storage_type == "riak":
        import riak
        riak_nodes = config.get("riak_nodes")
        riak_instance = riak.RiakClient(nodes=riak_nodes)
        storage = RiakStorage(riak_instance)
    elif storage_type == "redis":
        import redis
        redis_instance = redis.from_url(config.get("redis_url"))
        storage = RedisStorage(redis_instance)
    else:
        storage = MemoryStorage()
    server = msgpackrpc.Server(SifrServer(storage), unpack_encoding='utf-8')
    server.listen(
        msgpackrpc.Address(config.get("host", "127.0.0.1"),
                           int(config.get("port", 6000))))
    server.start()
Beispiel #10
0
    def start(self):
        try:
            server = msgpackrpc.Server(self.handler)

            def stop(num, stackframe):
                self.logger.critical("Server: get signal %s and stop", num)
                server.close()
                server.stop()
                exit(0)

            signal.signal(signal.SIGTERM, stop)
            signal.signal(signal.SIGINT, stop)

            self.logger.info('Server: listen: %s:%s', self.host, self.port)
            server.listen(msgpackrpc.Address(self.host, self.port, socket.AF_INET))
            server.start()
        except Exception as e:
            self.logger.error('Server: get exception: %s\n'
                              'traceback: %s', e.message, traceback.format_exc())
Beispiel #11
0
def main():
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    rc = libpy.config.readConfig('config.ini')
    config = {
        'SELF': {
            'host': rc.get_skv('SELF', 'host'),
            'port': rc.get_skv('SELF', 'port')
        },
        'RDB': {
            'host': rc.get_skv('RDB', 'host'),
            'port': rc.get_skv('RDB', 'port'),
            'user': rc.get_skv('RDB', 'user'),
            'password': rc.get_skv('RDB', 'password'),
            'dbname': rc.get_skv('RDB', 'dbname')
        }
    }
    sc = gobject.selfconfig.SelfConfig(**config)
    tuser = table.user.User()
    server = msgpackrpc.Server(tuser)
    server.listen(msgpackrpc.Address(sc.SELF['host'], sc.SELF['port']))
    server.start()
Beispiel #12
0
    def setup_env(self):
        def _on_started():
            self._server._loop.dettach_periodic_callback()
            lock.release()

        def _start_server(server):
            server._loop.attach_periodic_callback(_on_started, 1)
            server.start()
            server.close()

        self._server = msgpackrpc.Server(TestMessagePackRPC.TestServer())
        self._server.listen(self._address)
        self._thread = threading.Thread(target=_start_server,
                                        args=(self._server, ))

        lock = threading.Lock()
        self._thread.start()
        lock.acquire()
        lock.acquire()  # wait for the server to start

        self._client = msgpackrpc.Client(self._address,
                                         unpack_encoding='utf-8')
        return self._client
Beispiel #13
0
# Keras
N_FEATURES = 50000
MAXLEN = 140

DATA_DIR = '/work/rpc'
modelpath = os.path.join(DATA_DIR, 'sentiment_model.yaml')
with open(modelpath) as fd:
    model = model_from_yaml(fd.read())
model.compile(optimizer='adam',
              loss='binary_crossentropy',
              metrics=['accuracy'])
model.load_weights(os.path.join(DATA_DIR, 'sentiment_weights.hdf5'))


class SentimentAnalysis(object):
    def preprocessing(self, line):
        line = line.strip()
        X = [util.sentence2array(line, N_FEATURES)]
        return sequence.pad_sequences(X, maxlen=MAXLEN)

    def predict(self, x):
        x = self.preprocessing(x)
        return model.predict(x)[0][0]


if __name__ == "__main__":
    server = msgpackrpc.Server(SentimentAnalysis())
    server.listen(msgpackrpc.Address('0.0.0.0', 18798))
    server.start()
is_car_found = threading.Event()
is_follow = threading.Event()
is_stop = threading.Event()

class rpcServer(object):
    def push(self, result, timestamp):
        print("recv result={}; sender_time={}".format(result, timestamp))
        if 'car' in result:
            is_car_found.set()
            is_follow.set()

    def stop(self, result, timestamp):
        print('stop simulation')
        is_stop.set()

server = msgpackrpc.Server(rpcServer())


def actuator(server):
    server.listen(msgpackrpc.Address("172.17.15.21", 18800))
    server.start()
    server.close()

def control_drone1_move(is_stop):
    while 1:
        controller_thread = move_drone('Drone1', 45, 0, 0, 90, 5, async=True)
        time.sleep(10)
        controller_thread = move_drone('Drone1', -45, 0, 0, 90, 5, async=True)
        time.sleep(10)

def control_drone1_pic(is_stop):
Beispiel #15
0
import bpy
from mathutils import *
import math
import random
import msgpackrpc
import sys


class RenderServer(object):
    def renderImage(self, path, luku):
        random.seed()
        rotations = [(0, math.pi * 1.5, 0), (math.pi * 1, 0, 0),
                     (math.pi * 0.5, 0, 0), (math.pi * 1.5, 0, 0), (0, 0, 0),
                     (0, math.pi * 0.5, 0)]
        noppa = bpy.data.objects["Noppa"]
        noppa.rotation_mode = 'XYZ'
        noppa.rotation_euler = (rotations[luku])
        noppa.rotation_euler[2] = random.random() * 2 * math.pi
        noppa.location = (random.random() - 0.5, random.random() * 2 - 1, 0.50)
        bpy.data.scenes['Scene'].render.filepath = path
        bpy.data.scenes['Scene'].render.image_settings.file_format = 'JPEG'
        bpy.ops.render.render(write_still=True)

    def exit(self):
        sys.exit()


server = msgpackrpc.Server(RenderServer())
server.listen(msgpackrpc.Address("localhost", 18800))
server.start()
Beispiel #16
0
        cb = None

        if (self.tensorboard_callback != None):
            cb = [self.tensorboard_callback]

        train_epochs = 5

        self.model.fit(self.train_ds,
                       validation_data=self.val_ds,
                       shuffle=True,
                       epochs=self.epoch + train_epochs,
                       callbacks=cb,
                       initial_epoch=self.epoch,
                       use_multiprocessing=True)

        self.epoch = self.epoch + train_epochs

    def evaluate(self):
        results = self.model.evaluate(self.val_ds)
        print("test loss, test acc:", results)

    def exit(self):
        sys.exit()


if __name__ == '__main__':
    print("start")
    server = msgpackrpc.Server(TrainServer())
    server.listen(msgpackrpc.Address("localhost", 18801))
    server.start()
Beispiel #17
0
def run_server(ip, port):
    print('start DataForwarder at {}:{}'.format(ip, port))
    server = msgpackrpc.Server(DisplayServer())
    server.listen(msgpackrpc.Address(ip, port))
    server.start()
Beispiel #18
0
 def run(self):
     self.server = msgpackrpc.Server(TestService())
     self.server.listen(msgpackrpc.Address("localhost", PORT))
     self.server.start()
Beispiel #19
0
#logging
logging.basicConfig(level=logging.DEBUG)

# config
logging.info('Loading configuration')
settings = get_appsettings(argv[1], 'triage')

# mongo
logging.info('Connecting to mongo at: mongodb://' + settings['mongodb.host'] +
             '/' + settings['mongodb.db_name'])
mongoengine.connect(settings['mongodb.db_name'], host=settings['mongodb.host'])


class LoggingServer:
    def error(self, msg):
        try:
            error = Error.create_from_msg(msg)
            error.save()
        except Exception:
            logging.exception('Failed to process error')


logging.info('Creating server at ' + settings['errorserver.host'] + ':' +
             settings['errorserver.port'])
server = msgpackrpc.Server(LoggingServer())
server.listen(
    msgpackrpc.Address(settings['errorserver.host'],
                       settings['errorserver.port']))
logging.info('Serving!')
server.start()
                print(
                    "lxc-attach -n %s -- /bin/bash -c 'cd /var/www/shareddata%s && %s > /var/www/shareddata/%s/out.txt && echo 0 > /var/www/shareddata/%s/status.txt' "
                    % (image_id, path_to_file, cmd_line, jobname, jobname))
                os.system(
                    "lxc-attach -n %s -- /bin/bash -c 'cd /var/www/shareddata%s && %s > /var/www/shareddata/%s/out.txt && echo 0 > /var/www/shareddata/%s/status.txt' "
                    % (image_id, path_to_file, cmd_line, jobname, jobname))

                time.sleep(time_out)

                with open("/var/www/shareddata/%s/status.txt" % jobname,
                          "r") as fp:
                    status_now = fp.read()
                    if status_now == 0:
                        break
        return 0

    def delete(self, job_name):
        with open("/var/www/shareddata/%s/config.txt" % job_name, "r") as fp:
            image_id = fp.read()
        print(image_id)
        os.system("lxc-stop -n %s" % image_id)
        print(job_name)
        os.system("rm -rf /var/www/shareddata/%s" % job_name)
        # am i right...? rm -rf
        return 0


server = msgpackrpc.Server(deamon_server())
server.listen(msgpackrpc.Address("localhost", 8080))
server.start()
Beispiel #21
0
        vis_util.visualize_boxes_and_labels_on_image_array(
            image_np,
            output_dict['detection_boxes'],
            output_dict['detection_classes'],
            output_dict['detection_scores'],
            category_index,
            instance_masks=output_dict.get('detection_masks'),
            use_normalized_coordinates=True,
            line_thickness=8)
        im = Image.fromarray(image_np)
        im.save('abc.jpg')
        print("Done")
        return "Done"
        #except Exception as inst:

server = msgpackrpc.Server(InferenceServer())
server.listen(msgpackrpc.Address("localhost", 18800))
server.start()

# for image_path in TEST_IMAGE_PATHS:
#   image = Image.open(image_path)
#   # the array based representation of the image will be used later in order to prepare the
#   # result image with boxes and labels on it.
#   image_np = load_image_into_numpy_array(image)
#   # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
#   image_np_expanded = np.expand_dims(image_np, axis=0)
#   # Actual detection.
#   output_dict = run_inference_for_single_image(image_np, detection_graph)
#   # Visualization of the results of a detection.
#   vis_util.visualize_boxes_and_labels_on_image_array(
#       image_np,
   \ \/  \/ / _ \ |  _/ _ \| | | | '_ \ / _` |  / _` | | |      / /\ \ |  _  / 
    \  /\  /  __/ | || (_) | |_| | | | | (_| | | (_| | | |____ / ____ \| | \ \ 
     \/  \/ \___| |_| \___/ \__,_|_| |_|\__,_|  \__,_|  \_____/_/    \_\_|  \_\ 

                      ___..............._
             __.. ' _'.""" """\\""" """""- .`-._
 ______.-'         (_) |      \\           ` \\`-. _
/_       --------------'-------\\---....______\\__`.`  -..___
| T      _.----._           Xxx|x...           |          _.._`--. _
| |    .' ..--.. `.         XXX|XXXXXXXXXxx==  |       .'.---..`.     -._
\_j   /  /  __  \  \        XXX|XXXXXXXXXXX==  |      / /  __  \ \        `-.
 _|  |  |  /  \  |  |       XXX|""'            |     / |  /  \  | |          |
|__\_j  |  \__/  |  L__________|_______________|_____j |  \__/  | L__________J
     `'\ \      / ./__________________________________\ \      / /___________\ 
     `.`----'.'   dp                                `.`----'.'
          `""" "'                                         `" """'
"""


class FileServer(object):
    def push(self, result, timestamp):
        if 'car' in result:
            print(display_text)
        return 'received {} bytes'.format(len(result))


# print(display_text)
server = msgpackrpc.Server(FileServer())
server.listen(msgpackrpc.Address('172.17.51.5', 18900))
print('start display service on 172.17.51.5:18900')
server.start()
Beispiel #23
0
        g = np.frombuffer(data[b'g'], dtype=np.uint8)
        b = np.frombuffer(data[b'b'], dtype=np.uint8)
        r.resize((h, w))
        g.resize((h, w))
        b.resize((h, w))
        img[:, :, 0] = b
        img[:, :, 1] = g
        img[:, :, 2] = r
        result = {"model": "yolo", "objects": []}
        result["objects"].append({
            "class": "mouse",
            "xmin": 200,
            "ymin": 200,
            "width": 100,
            "height": 100
        })
        result["objects"].append({
            "class": "mouse",
            "xmin": 150,
            "ymin": 150,
            "width": 50,
            "height": 50
        })
        print(result)
        return json.dumps(result)


server = msgpackrpc.Server(ImageProcess())
server.listen(msgpackrpc.Address("127.0.0.1", 8800))
server.start()
Beispiel #24
0
# https://github.com/msgpack-rpc/msgpack-rpc-python#server
import msgpackrpc


class SumServer(object):
    def sum(self, x, y):
        return x + y


server = msgpackrpc.Server(SumServer())
server.listen(msgpackrpc.Address("localhost", 18800))
server.start()
Beispiel #25
0
def run_server(ip, port, forward_to_ip, forward_to_port):
    print('start ColorFinder at {}:{}'.format(ip, port))
    server = msgpackrpc.Server(ColorFinder(forward_to_ip, forward_to_port))
    server.listen(msgpackrpc.Address(ip, port))
    server.start()
Beispiel #26
0
 def __init__(self):
     self._server = msgpackrpc.Server(self)
     self._blocking_thread = None
     self._id = str(uuid.uuid1())
Beispiel #27
0
def main():
    server = msgpackrpc.Server(PropertyServer())
    server.listen(msgpackrpc.Address("localhost", 18800))
    print("start serving...")
    server.start()
Beispiel #28
0
import msgpackrpc

class EchoHandler(object):

    def Echo123(self, msg):
        (msg1, msg2, msg3) = msg
        return ("1:%s 2:%s 3:%s" % (msg1, msg2, msg3))

    def EchoStruct(self, msg):
        return ("msg:%s" % msg)

if __name__ == '__main__':
        addr = msgpackrpc.Address('localhost', 9000)
        server = msgpackrpc.Server(EchoHandler())
        server.listen(addr)
        server.start()
Beispiel #29
0
import msgpackrpc


class Something(object):
    def ListTest(self, name, position):
        for i in range(len(name)):
            print type(name[i]), name[i], type(position[i]), position[i]


server = msgpackrpc.Server(Something())
server.listen(msgpackrpc.Address("", 18800))
server.start()
Beispiel #30
0
    def __init__ (self):
        super().__init__()
        self.adaptors = {}

    def register_adaptor (self, adaptor):
        self.adaptors[adaptor.tickerid] = adaptor

    def ohlcv (self, tickerid, resolution, count):
        return self.adaptors[tickerid].ohlcv(resolution, count)
        
    def step_ohlcv (self, tickerid, resolution, next_clock):
        return self.adaptors[tickerid].step_ohlcv(resolution, next_clock)

if __name__ == '__main__':
    import os
    from gevent.server import StreamServer
    from pine.market.bitmex import BitMexOhlcAdaptor
    from pine.market.bitflyer import BitFlyerOhlcAdaptor
    from pine.market.base import PROXY_PORT

    server = OhlcvProxyServer()
    server.register_adaptor(BitMexOhlcAdaptor())
    server.register_adaptor(BitFlyerOhlcAdaptor())

    port = int(os.environ.get('PORT', PROXY_PORT))
    #server = StreamServer(('127.0.0.1', port), server)
    #server.serve_forever()
    server = msgpackrpc.Server(server, unpack_encoding='utf-8')
    server.listen(msgpackrpc.Address('127.0.0.1', port))
    server.start()