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.')
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.')
pokemon = { 'encounter_id': 93253523, 'spawn_id': 3502935, 'pokemon_id': pokemon_id, 'form': args.form, 'time_till_hidden': tth, 'lat': lat, 'lon': lon, 'individual_attack': randint(0, 15), 'individual_defense': randint(0, 15), 'individual_stamina': randint(0, 15), 'seen': now, 'move_1': choice(MOVES), 'move_2': choice(MOVES), 'valid': True, 'expire_timestamp': now + tth } notifier = Notifier() loop = get_event_loop() if loop.run_until_complete(notifier.notify(pokemon, randint(1, 2))): print('Success') else: print('Failure') SessionManager.close() loop.close()
now = time.time() pokemon = { 'encounter_id': 93253523, 'spawn_id': 3502935, 'pokemon_id': pokemon_id, 'time_till_hidden': tth, 'lat': lat, 'lon': lon, 'individual_attack': randint(0, 15), 'individual_defense': randint(0, 15), 'individual_stamina': randint(0, 15), 'seen': now, 'move_1': choice(MOVES), 'move_2': choice(MOVES), 'valid': True, 'expire_timestamp': now + tth } notifier = Notifier() loop = get_event_loop() if loop.run_until_complete(notifier.notify(pokemon, randint(1, 2))): print('Success') else: print('Failure') SessionManager.close() loop.close()