コード例 #1
0
 def setUpClass(cls):
     cls.config = testing.setUp()
     settings = {}
     try:
         fileConfig(cls.get_ini())
     except NoSectionError:
         pass
     load_into_settings(cls.get_ini(), settings)
     cls.config.add_settings(settings)
     metlog_wrapper = load_from_settings('metlog',
                                         cls.config.registry.settings)
     for logger in ('tokenserver', 'mozsvc', 'powerhose'):
         hook_logger(logger, metlog_wrapper.client)
     cls.config.registry['metlog'] = metlog_wrapper.client
     cls.config.include("tokenserver")
     load_and_register("tokenserver", cls.config)
     cls.backend = cls.config.registry.getUtility(INodeAssignment)
     cls.cluster = get_cluster(
         'tokenserver.tests.mockworker.crypto_worker',
         numprocesses=1,
         background=True,
         # debug=True,
         worker_params={'config': cls.get_ini()})
     cls.cluster.start()
     time.sleep(1.)
コード例 #2
0
    def _get_cluster(self, callable, **kw):
        logger.debug('getting cluster')
        front = 'ipc:///tmp/f-%s' % callable
        back = 'ipc:///tmp/b-%s' % callable
        hb = 'ipc:///tmp/h-%s' % callable
        reg = 'ipc:///tmp/r-%s' % callable

        cl = get_cluster(callable,
                         frontend=front,
                         backend=back,
                         heartbeat=hb,
                         register=reg,
                         numprocesses=1,
                         background=True,
                         debug=True,
                         timeout=client.DEFAULT_TIMEOUT_MOVF,
                         **kw)
        cl.start()
        time.sleep(1.)  # stabilization
        self.clusters.append(cl)
        logger.debug('cluster ready')
        return client.Pool(size=3,
                           frontend=front,
                           debug=True,
                           timeout=client.DEFAULT_TIMEOUT,
                           timeout_max_overflow=client.DEFAULT_TIMEOUT_MOVF,
                           timeout_overflows=client.DEFAULT_TIMEOUT_OVF)
コード例 #3
0
ファイル: bench.py プロジェクト: bearrito/powerhose
def _run_cluster():
    cluster = get_cluster('bench.sign', debug=False,
                          numprocesses=_PROC,
                          logfile='/tmp/phose')
    try:
        cluster.start()
    finally:
        cluster.stop()
コード例 #4
0
def _run_cluster():
    cluster = get_cluster('bench.sign',
                          debug=False,
                          numprocesses=_PROC,
                          logfile='/tmp/phose')
    try:
        cluster.start()
    finally:
        cluster.stop()
コード例 #5
0
ファイル: test_cluster.py プロジェクト: pjenvey/powerhose
 def _get_cluster(self, callable, **kw):
     logger.debug('getting cluster')
     front = 'ipc:///tmp/f-%s' % callable
     back = 'ipc:///tmp/b-%s' % callable
     hb = 'ipc:///tmp/h-%s' % callable
     cl = get_cluster(callable, frontend=front, backend=back, heartbeat=hb,
                      numprocesses=1, background=True, debug=True,
                      timeout=client.DEFAULT_TIMEOUT_MOVF, **kw)
     cl.start()
     time.sleep(1.)  # stabilization
     self.clusters.append(cl)
     logger.debug('cluster ready')
     return client.Client(front, debug=True, timeout=client.DEFAULT_TIMEOUT,
             timeout_max_overflow=client.DEFAULT_TIMEOUT_MOVF,
             timeout_overflows=client.DEFAULT_TIMEOUT_OVF)
コード例 #6
0
ファイル: test_powerhose.py プロジェクト: hfeeki/tokenserver
 def setUpClass(cls):
     cls.config = testing.setUp()
     settings = {}
     try:
         fileConfig(cls.get_ini())
     except NoSectionError:
         pass
     load_into_settings(cls.get_ini(), settings)
     cls.config.add_settings(settings)
     metlog_wrapper = load_from_settings('metlog',
             cls.config.registry.settings)
     for logger in ('tokenserver', 'mozsvc', 'powerhose'):
         hook_logger(logger, metlog_wrapper.client)
     cls.config.registry['metlog'] = metlog_wrapper.client
     cls.config.include("tokenserver")
     load_and_register("tokenserver", cls.config)
     cls.backend = cls.config.registry.getUtility(INodeAssignment)
     cls.cluster = get_cluster('tokenserver.tests.mockworker.crypto_worker',
                               numprocesses=1, background=True,
                               #debug=True,
                               worker_params={'config': cls.get_ini()})
     cls.cluster.start()
     time.sleep(1.)
コード例 #7
0
ファイル: crypto.py プロジェクト: bearrito/powerhose
from powerhose.util import set_logger
from powerhose import get_cluster


set_logger(True)
cluster = get_cluster('crypto_worker.sign')
try:
    cluster.start()
finally:
    cluster.stop()
from powerhose.util import set_logger
from powerhose import get_cluster

set_logger(True)
cluster = get_cluster('crypto_worker.sign')
try:
    cluster.start()
finally:
    cluster.stop()
コード例 #9
0
ファイル: sign.py プロジェクト: tarekziade/signpic
def main():
    signature  = os.path.join(os.path.expanduser('~'), '.signature.jpg')
    if not os.path.exists(signature):
        signature = os.path.join(os.path.dirname(__file__), 'signature.jpg')

    parser = argparse.ArgumentParser(description='Sign some pictures.')

    parser.add_argument('pic', help="Directory or single picture.",
                        action='store')

    parser.add_argument('--signature',
                        help=("Signature file. If not given, will look at "
                              "~/.signature.jpg then fallback to the "
                              "included signature."),
                        default=signature)

    parser.add_argument('--debug', action='store_true', default=False,
                        help="Debug mode")

    parser.add_argument('--phose', action='store_true', default=False,
                        help="Use Powerhose")

    parsed = parser.parse_args()

    import logging

    if parsed.debug:
        level = logging.DEBUG
    else:
        level = logging.INFO

    logger.setLevel(level)
    ch = logging.StreamHandler()

    if parsed.debug:
        ch.setLevel(level)
    else:
        ch.setLevel(level)

    formatter = logging.Formatter('[%(asctime)s][%(name)s] %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    phose_logger = logging.getLogger('powerhose')
    phose_logger.addHandler(ch)

    queue = Queue.Queue()

    if not os.path.exists(parsed.pic):
        print("%r does not seem to exist" % parsed.pic)
        sys.exit(1)

    logger.info('Using signature file %r' % parsed.signature)

    # looking for files
    if os.path.isdir(parsed.pic):
        logger.info('Looking for files in %r' % parsed.pic)
        finder = FileFinder(parsed.pic, queue)
        finder.start()
        time.sleep(.1)      # give it a chance to start
    else:
        finder = None
        queue.put(parsed.pic)

    # run the cluster
    if parsed.phose and finder is not None:
        from powerhose import get_cluster
        from powerhose.client import Pool
        pool = Pool(timeout=30.)
        logger.debug('Starting the PowerHose cluster')
        cluster = get_cluster('signpic.sign.apply_signature', background=True)
        cluster.start()
        time.sleep(1.)
    else:
        if parsed.phose:
            logger.warning('Not using --phose for a single picture!')
        pool = None

    try:
        workers = [Worker(queue, pool, parsed.signature,
                          parsed.phose) for i in range(10)]

        for worker in workers:
            worker.start()

        if finder is not None:
            finder.join()

        for worker in workers:
            worker.join()
    finally:
        if parsed.phose:
            cluster.stop()

    sys.stdout.write('Done.\n')
from powerhose import get_cluster
from powerhose.client import Client


cluster = get_cluster('echo_worker.echo', background=True)
cluster.start()

client = Client()

for i in range(10):
    print client.execute(str(i))

cluster.stop()