From 5b4adb011bedca13b5437a3d31a9b64129f098a3 Mon Sep 17 00:00:00 2001 From: Modrzew Date: Fri, 12 Aug 2016 13:14:34 +0200 Subject: [PATCH] Guard against set changing size --- worker.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/worker.py b/worker.py index 2166d37839..c15f87ab1a 100644 --- a/worker.py +++ b/worker.py @@ -464,7 +464,11 @@ def check(self): time.sleep(0.5) # OK, now we're killed while True: - tasks = sum([not t.done() for t in asyncio.Task.all_tasks(loop)]) + try: + tasks = sum(not t.done() for t in asyncio.Task.all_tasks(loop)) + except RuntimeError: + # Set changed size during iteration + tasks = '?' print( '{} coroutines active'.format(tasks), end='\r' @@ -505,6 +509,11 @@ def get_status_message(self): dots.append(worker.error_code[0]) else: dots.append('.' if worker.step % 2 == 0 else ':') + try: + coroutines_count = len(asyncio.Task.all_tasks(self.loop)) + except RuntimeError: + # Set changed size during iteration + coroutines_count = '?' output = [ 'PokeMiner\trunning for {}'.format(running_for), '{len} workers, each visiting ~{avg} points per cycle ' @@ -517,7 +526,7 @@ def get_status_message(self): '', '{} threads and {} coroutines active'.format( threading.active_count(), - len(asyncio.Task.all_tasks(self.loop)), + coroutines_count, ), 'API latency: min {min:.3f}, max {max:.3f}, avg {avg:.3f}'.format( **time_stats['api_calls']