Ejemplo n.º 1
0
def cleanup(overseer, manager):
    try:
        if hasattr(overseer, 'print_handle'):
            overseer.print_handle.cancel()
        if hasattr(overseer, 'worker30'):
            overseer.worker30.cancel()
        if hasattr(overseer, 'worker_raider'):
            overseer.worker_raider.cancel()
        overseer.running = False
        print('Exiting, please wait until all tasks finish')

        log = get_logger('cleanup')
        print('Finishing tasks...')

        LOOP.create_task(overseer.exit_progress())
        pending = gather(*Task.all_tasks(loop=LOOP), return_exceptions=True)
        try:
            LOOP.run_until_complete(wait_for(pending, 40))
        except TimeoutError as e:
            print('Coroutine completion timed out, moving on.')
        except Exception as e:
            log = get_logger('cleanup')
            log.exception('A wild {} appeared during exit!',
                          e.__class__.__name__)

        db_proc.stop()
        overseer.refresh_dict()

        print('Dumping pickles...')
        dump_pickle('accounts', get_accounts())
        dump_pickle('accounts30', get_accounts30())
        FORT_CACHE.pickle()
        altitudes.pickle()
        if conf.CACHE_CELLS:
            dump_pickle('cells', Worker.cells)

        spawns.pickle()
        while not db_proc.queue.empty():
            pending = db_proc.queue.qsize()
            # Spaces at the end are important, as they clear previously printed
            # output - \r doesn't clean whole line
            print('{} DB items pending     '.format(pending), end='\r')
            sleep(.5)
    finally:
        print('Closing pipes, sessions, and event loop...')
        manager.shutdown()
        SessionManager.close()
        close_sessions()
        LOOP.close()
        print('Done.')
Ejemplo n.º 2
0
def cleanup(overseer, manager):
    try:
        overseer.print_handle.cancel()
        overseer.running = False
        print('Exiting, please wait until all tasks finish')

        log = get_logger('cleanup')
        print('Finishing tasks...')

        LOOP.create_task(overseer.exit_progress())
        pending = gather(*Task.all_tasks(loop=LOOP), return_exceptions=True)
        try:
            LOOP.run_until_complete(wait_for(pending, 40))
        except TimeoutError as e:
            print('Coroutine completion timed out, moving on.')
        except Exception as e:
            log = get_logger('cleanup')
            log.exception('A wild {} appeared during exit!', e.__class__.__name__)

        db_proc.stop()
        overseer.refresh_dict()

        print('Dumping pickles...')
        dump_pickle('accounts', ACCOUNTS)
        FORT_CACHE.pickle()
        altitudes.pickle()
        if conf.CACHE_CELLS:
            dump_pickle('cells', Worker.cells)

        spawns.pickle()
        while not db_proc.queue.empty():
            pending = db_proc.queue.qsize()
            # Spaces at the end are important, as they clear previously printed
            # output - \r doesn't clean whole line
            print('{} DB items pending     '.format(pending), end='\r')
            sleep(.5)
    finally:
        print('Closing pipes, sessions, and event loop...')
        manager.shutdown()
        SessionManager.close()
        close_sessions()
        LOOP.close()
        print('Done.')