Beispiel #1
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    address = sys.argv[1]
    service = Service(address)

    service.register('test', test)
    service.start()
Beispiel #2
0
def start_service(addr, n):
    """ Start a service """
    s = Service(addr)
    s.register('add', lambda x, y: x + y)

    started = time.time()
    for _ in range(n):
        s.process()
    duration = time.time() - started

    time.sleep(0.1)
    print('Service stats:')
    util.print_stats(n, duration)
    return
def start_service(addr, n):
    """ Start a service """
    s = Service(addr)

    started = time.time()
    for _ in range(n):
        msg = s.sock.recv()
        s.sock.send(msg)
    s.sock.close()
    duration = time.time() - started

    print('Raw REP service stats:\n')
    util.print_stats(n, duration)
    return
Beispiel #4
0
Datei: core.py Projekt: richwu/oi
    def __init__(self, description, address):
        super(Program, self).__init__(description, address)

        self.service = Service(address) if address else None
        self.config = compat.configparser.ConfigParser()

        # Add the flag for parsing configuration file
        self.parser.add_argument('--config',
                                 help='configuration file to use',
                                 nargs='?')

        if self.service is None:
            return

        # Add default service worker, which will respond to ctl commands
        # Other workers will perform other kind of work, such as
        # fetching resources from the web, etc
        self.workers.append(worker.ServiceWorker(self.service))

        # Add default commands
        self.add_command('ping', lambda: 'pong')
        self.add_command('help', self.help_function)
Beispiel #5
0
import logging
from nanoservice import Service


def greet(name):
    return 'Hello {}'.format(name)


def add(x, y):
    return x + y


s = Service('ipc:///tmp/service.sock')
s.register('greet', greet)
s.register('add', add)
s.start()
 def setUp(self):
     addr = 'inproc://test'
     self.client = Client(addr)
     self.service = Service(addr)
     self.service.register('divide', lambda x, y: x / y)
     self.service.register('echo', lambda x: x)
Beispiel #7
0
 def start_service(self, addr):
     s = Service(addr)
     s.register('divide', lambda x, y: x / y)
     s.start()