コード例 #1
0
def run(amqp_uri, exchange, routing_key, params):
    # start a monitor output thread, this does the work, whilst the main thread just acts
    # as a control thread to receive the  keyboard input

    worker = Worker(amqp_uri, exchange, routing_key)
    worker.delay_between_refreshes = params['--delay'] if params[
        '--delay'] is not None else DELAY_BETWEEN_REFRESHES
    worker.limit = params['--updates'] if params[
        '--updates'] is not None else DISPLAY_N_TIMES
    worker.page_size = params['--pagesize'] if params[
        '--pagesize'] is not None else PAGE_SIZE
    worker.run()

    # poll for keyboard input to allow the user to quit monitoring
    while True:
        try:
            # just sleep unless we receive an interrupt i.e. CTRL+C
            sleep(KEYBOARD_INTERRUPT_SLEEP)
        except KeyboardInterrupt:
            worker.stop()
            sys.exit(1)