Example #1
0
def main(options):
    if options['--silent']:
        try:
            outfile = os.open(os.devnull, os.O_WRONLY)
            os.close(sys.stderr.fileno())
            os.dup2(outfile, sys.stderr.fileno())
        finally:
            os.close(outfile)

    display = xutil.get_display()
    screen = display.screen()
    window_infos = xutil.get_parent_window_infos()
    loop = asyncio.get_event_loop()
    executor = thread.DaemonThreadPoolExecutor(max_workers=2)
    parser_object = (parser.ParserOption(options['--parser'])
                     .parser_class())
    image_loader = (loading.ImageLoaderOption(options['--loader'])
                    .loader_class())
    error_handler = error_processor_factory(parser_object)
    view = View()
    tools = Tools(image_loader, parser_object, error_handler)
    window_factory = ui.OverlayWindow.Factory(display, view)
    windows = batch.BatchList(window_factory.create(*window_infos))
    image_loader.register_error_handler(error_handler)
    view.screen_width = screen.width_in_pixels
    view.screen_height = screen.height_in_pixels

    if tmux_util.is_used():
        atexit.register(setup_tmux_hooks())
        view.offset = tmux_util.get_offset()

    with windows, image_loader:
        loop.set_default_executor(executor)

        for sig in (signal.SIGINT, signal.SIGTERM):
            loop.add_signal_handler(
                sig, shutdown_factory(loop))

        loop.add_signal_handler(
            signal.SIGUSR1,
            lambda: asyncio.ensure_future(query_windows(
                window_factory, windows, view)))

        loop.add_signal_handler(
            signal.SIGWINCH,
            lambda: asyncio.ensure_future(
                reset_terminal_info(windows)))

        asyncio.ensure_future(process_xevents(loop, display, windows))
        asyncio.ensure_future(process_commands(
            loop, shutdown_factory(loop),
            windows, view, tools))

        try:
            loop.run_forever()
        finally:
            loop.close()
            executor.shutdown(wait=False)
Example #2
0
def main_layer(options):
    display = xutil.get_display()
    window_infos = xutil.get_parent_window_infos()
    loop = asyncio.get_event_loop()
    executor = futures.ThreadPoolExecutor(max_workers=2)
    shutdown_routine = shutdown(loop)  #pylint: disable=E1111
    parser_class = parser.ParserOption(options['--parser']).parser_class
    media = {}
    window_factory = ui.OverlayWindow.Factory(display, media)
    windows = batch.BatchList(window_factory.create(*window_infos))

    if tmux_util.is_used():
        atexit.register(setup_tmux_hooks())

    with windows:
        # this could lead to unexpected behavior,
        # but hey otherwise it breaks exiting the script..
        # as readline for example won't return till a line was read
        # and there's no (already integrated) way to
        # disable it only for a specific threadpoolexecutor
        # see: https://github.com/python/cpython/blob/master/Lib/concurrent/futures/thread.py#L33
        # -> TODO: reimplement ThreadPoolExecutor
        atexit.unregister(futures.thread._python_exit)  #pylint: disable=W0212
        loop.set_default_executor(executor)

        for sig in (signal.SIGINT, signal.SIGTERM):
            loop.add_signal_handler(
                sig, functools.partial(asyncio.ensure_future,
                                       shutdown_routine))

        loop.add_signal_handler(
            signal.SIGUSR1, lambda: asyncio.ensure_future(
                query_windows(window_factory, windows)))

        asyncio.ensure_future(main_xevents(loop, display, windows))
        asyncio.ensure_future(
            main_commands(loop, shutdown_routine, parser_class(), windows,
                          media))

        try:
            loop.run_forever()
        finally:
            loop.close()
            executor.shutdown(wait=False)
Example #3
0
def main_layer(options):
    display = xutil.get_display()
    window_infos = xutil.get_parent_window_infos()
    loop = asyncio.get_event_loop()
    executor = thread.DaemonThreadPoolExecutor(max_workers=2)
    parser_class = parser.ParserOption(options['--parser']).parser_class
    view = ui.View()
    window_factory = ui.OverlayWindow.Factory(display, view)
    windows = batch.BatchList(window_factory.create(*window_infos))

    if tmux_util.is_used():
        atexit.register(setup_tmux_hooks())
        view.offset = tmux_util.get_offset()

    if options['--silent']:
        sys.stderr = open('/dev/null', 'w')

    with windows:
        loop.set_default_executor(executor)

        for sig in (signal.SIGINT, signal.SIGTERM):
            loop.add_signal_handler(
                sig, shutdown_factory(loop))

        loop.add_signal_handler(
            signal.SIGUSR1,
            lambda: asyncio.ensure_future(query_windows(
                window_factory, windows, view)))

        asyncio.ensure_future(main_xevents(loop, display, windows))
        asyncio.ensure_future(main_commands(
            loop, shutdown_factory(loop), parser_class(),
            windows, view))

        try:
            loop.run_forever()
        finally:
            loop.close()
            executor.shutdown(wait=False)